News flash: I'm going to Australia in February, so this Web site may be switched off at any time.


Branching in Icon

Here's a short program that illustrates conditional branches in Icon:

    procedure main()
      if  1 < 2  then
        write ( "One is less than two" )
      else
        write ( "One is greater than two" );
    end
The general form is ``if e1 then e2 else e3'', meaning ``if e1 produces at least one result, evaluate e2, otherwise evaluate e3.''

The less-than operator (e1<e2) means, ``if e1 is less than e2, produce the value of e2, otherwise produce no values at all.''

An Icon expression that produces no values is said to fail. This concept of failure is actually one of the cleanest and most useful features of Icon, in the author's opinion.


Next: The joys of failure in Icon
See also: Using the Icon programming language
Previous: Using arguments in Icon procedures

John W. Shipman, john@nmt.edu