Matvec Users’ Guide
Matvec Users' Guide
Matvec Users' Guide
- No tags were found...
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Chapter 4<br />
Program Flow Control<br />
The program flow-control statements provided by <strong>Matvec</strong> are quite rich: if, while, for, break, continue, repeat,<br />
and null. They are similar to those in the C/C++ language:<br />
A BLOCK construction is defined as either a single statement or a sequence of statements (not necessary<br />
to be in the same line) enclosed with braces. For instance<br />
x = 8;<br />
is a BLOCK, and<br />
{<br />
}<br />
a = 6;<br />
b = sample(3,5);<br />
is a BLOCK, too.<br />
4.1 If–Endif and If–Else Statements<br />
The if statement has two forms:<br />
if (expression) BLOCK1 endif<br />
if (expression) BLOCK1 else BLOCK2<br />
The expression must evaluate to a scalar, otherwise a run-time error will result.<br />
In the first form of if statement, it simply performs a test on the expression in the parenthesis, and if<br />
the expression evaluates to a non-zero scalar, the statement(s) in BLOCK will be executed. The endif is<br />
mandatory to tell <strong>Matvec</strong> interpreter not to expect an else-branch.<br />
In the second form of if statement, it performs a test on the expression in the parenthesis, and if the<br />
expression is true then executes BLOCK1 otherwise execute BLOCK2.<br />
A nested if is an if that is the part of a BLOCK belonging to another if or else. In <strong>Matvec</strong> an elsebranch<br />
always refers to the nearest if statement that is within the same block as the else and is not already<br />
associated with an if. For example,<br />
if (i) {<br />
if (j) BLOCK1 endif;<br />
if (k) BLOCK2 else BLOCK3<br />
}<br />
else {<br />
BLOCK4<br />
}<br />
35