Getting Started Documentation Glish Learn More Programming Contact Us
Version 1.9 Build 1556
News FAQ
Search Home


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


Conditionals

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

if ( expression ) statement

if ( expression ) statement1 else statement2
An if statement evaluates expression, converts the result to a boolean value, and if true executes statement. The if ... else statement is similar, executing statement1 if the value is true and statement2 if false. The 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"


next up previous contents index
Next: Loops Up: Statements Previous: Printing   Contents   Index
Please send questions or comments about AIPS++ to aips2-request@nrao.edu.
Copyright © 1995-2000 Associated Universities Inc., Washington, D.C.

Return to AIPS++ Home Page
2006-10-15