ILabPascal - Control Structures

Command Explanation & Details
begin
  <statements>
end;
 
Defines a block of statements; in general, the begin...end block can be omitted if the block of statements consists only of a single statement.
if <expr>
  then <statement1>
  else <statement2>;
 
Decision based on the boolean value of the expression expr. If expr evaluates to a TRUE state the then clause is executed (statement 1), if expr results in FALSE then else clause is executed (statement 2).
for <cnt:=StartIx> to <EndIx> do
  begin
  <statements>
  end;
The for statement assigns the value of StartIx to the counter Cnt, then executes statements repeatedly, incrementing the counter after each iteration until it reaches EndIx. Please note that the parameter StartIx has to be less than or equal to EndIx, otherwise statements will never be executed.
for <cnt:=StartIx> downto <EndIx> do
  begin
  <statements>
  end;
The for statement assigns the value of StartIx to the counter Cnt, then executes statements repeatedly, decrementing the counter after each iteration until it reaches EndIx. Please note that the parameter StartIx has to be greater than or equal to EndIx, otherwise statements will never be executed.
while <expr> do
  begin
  <statements>
  end;
A while statement is a loop structure which evaluates the control condition expr before the first execution of the statement sequence. Hence, if the expr is false, the statement sequence is never executed.
case <expr> of
  alt1: <statement1>;
  alt2: <statement2>;
  alt3: <statement3>;
  ...
  else <statementn>
end;
 
The case statement provides a more readable alternative to deeply nested if statements. The selector expr is any expression of an ordinal type, the alternatives alt1..altN must be of the same type as the selector. If none of the alternatives matches the selector expression, then the statements in the else clause (if there is one) are executed.
repeat
  <statements>
until <expr>;
The repeat statement executes its sequence of constituent statements continually, testing expr after each iteration. When expr returns True, the repeat statement terminates. The sequence is always executed at least once, because expr is not evaluated until after the first iteration.


Last Update: 2020-Jšn-04