next up previous contents index
Next: Loops Up: Statements Previous: Printing

Conditionals

 

    Glish provides C-style if and if tex2html_wrap_inline15512 else conditionals:

if ( expression ) statement

if ( expression ) statementtex2html_wrap_inline15496 else statementtex2html_wrap_inline15498

An if statement evaluates expression, converts the result to a boolean value, and if true executes statement.     if tex2html_wrap_inline15512 else is similar, executing statementtex2html_wrap_inline15496 if the value is true and statementtex2html_wrap_inline15498 if false. expression should evaluate to a   scalar value; if it is a vector then its first element is tested, though   in the future an error may be generated instead.

    As in most languages, a ``dangling-else" is associated with the nearest previous if, so

    if ( x )
        if ( y )
            print "x and y"
        else
            print "either not x or not y"
is interpreted as:
    if ( x )
        {
        if ( y )
            print "x and y"
        else
            print "either not x or not y"
        }
and not as:
    if ( x )
        {
        if ( y )
            print "x and y"
        }
    else
        print "either not x or not y"
 



Thu Nov 13 16:44:05 EST 1997