Your Ad Here

Conditionals in Io

Was playing a little with Io. I like one of the options for the conditional if; you can basically just pass “if” three arguments; a statement, something to do if it’s true, and something to do if it’s false.

So you can do simply:


Io> a := 3
==> 3
Io> if(a%2==0, writeln("a is even"), writeln("a is odd"))
a is odd
==> nil

I know, in ruby you could just do a%2==0?"a is even":"a is odd", and similar in other languages. I do like the idea of if looking like a function to which I’m passing arguments, though. Just seems intuitive, somehow.

2 Responses to “Conditionals in Io”


  1. 1 mrben

    Looks very much like how you do it in Excel (and other spreadsheets ;) ). Personally, I don’t think it is as intuitive - I’d like to see what happens when you have to pass multiple statements to it, or nest multiple if/then/elses.

  2. 2 Phil Crissman

    I’d have to play with it a little more. Also, as I consider my use of the word “intuitive”, I suppose I’d need to expand that to “intuitive in a way that I hadn’t considered previously”, which could be open to the interpretation that it isn’t really that intuitive after all. Or, that it’s intuitive after you know how it works, which is a bit of a tautology itself.

    Then again, it’s always possible that I simply fell for the lure of something new and shiny… it’s not as though that’s never happened. ;-)

    But from a cursory look, I do like Io, it’s quite interesting. What would I use it for? I’ve no idea, at this point. But not everything needs to be completely utilitarian…

Comments are currently closed.

Your Ad Here