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


next up previous
Next: Records and Attributes Up: NOTE 195 Getting Started with Glish for AIPS++ Previous: Scripts and Functions

Loops and Conditionals

Three familiar program flow control statements are available in glish, ``if/else'', ``while'', and ``for'' loop statements. The general syntax for each is

if (<boolean condition>) {
    statements
} else {			# there is no 'else if'
    other statements
}

while (<boolean condition>) {
    execute all of this
}

for ( <variable> in <vector> ) {
    execute all of this
}

The ``for'' loop is a bit different to its equivalents in Fortran and C in the sense that the running variable doesn't have to make equal steps. It just takes on the values of the elements of the vector in succession, whatever those values may be. A garden variety loop of i from 1 to 10 in steps of 1 is

for (i in 1:10) {
}

Every method you can think of for generating a vector can be used to create the vector argument in the ``for'' statement. For example, you can use the 'seq()' built-in function to step from 3.66 to 7.35 in steps of 0.0123.

for (x in seq(3.66, 7.35, 0.0123)) {
}

Even a boolean vector is OK.

for (i in [F, T, T, F, T]) {
    print i;
}


next up previous
Next: Records and Attributes Up: NOTE 195 Getting Started with Glish for AIPS++ Previous: Scripts and Functions
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