Program Control Structures

Control structures effect the flow of simulation code. Though many of these structures function the same as their counterparts in C, the syntax is slightly different in each case. The main difference is that the statement being tested is not (necessarily) surrounded by parentheses, but is followed by a colon (':') character.

Control statements evaluate test statements and then execute code according to the result. In the case of for ([link]), foreach ([link]) and while ([link]), these structures are used as loops to repeat execution of a piece of code a certain number of times or while a certain condition is met. The if statement is used to execute a block of code if a certain condition is true or, optionally, a different block of code if the statement is false. A call to return will exit any control structure block immediately, as well as the method to which it belongs.

The conditional statements are comprised of C-style comparison operators. The following comparison operators are available:

  • ==, Equals

  • !=, Not equals

  • >=, Greater than or Equals

  • <=, Less than or Equals

  • >, Greater than

  • <, Less than

  • &&, And (short circuit operator)

  • ||, Or (short circuit operator)

  • !, Negation

For all of these structures, the code to be executed may be either a single statement, or several statements enclosed in braces ('{' and '}').