Compound statements

Explains the use of compound statements in OPL syntax.

A compound statement is a sequence of statements and expressions enclosed in curly brackets ({}). It can be used to perform multiple tasks whenever a single statement is expected, for example, in the following conditional statement, the three statements and expressions in curly brackets are executed when the condition a > b is true:


if (a > b) {
 var c = a
  a = b
  b = c
} 

The last statement or expression before a closing curly bracket does not need to be followed by a semicolon, even if it is on the same line. For example, the following program is syntactically correct and is equivalent to the previous one:


if (a > b) { var c = a; a = b; b = c }