Loops
Usage
- begin - end keywords are optional (for single-statement blocks).
- Semicolons are optional for the last statement in a begin - end block.
Syntaxrepeat
while (expr) do
statement;
while (expr) do
begin
statement;
statement { Semicolon optional for last statement in block }
end;
Syntaxfor
repeatUsage
statements;
until (expr);
- begin - end keywords are not needed for multiple-statement blocks.
SyntaxLoop control statements
for VAR := initial-value to final-value doExamples
statement;
for VAR := initial-value downto final-value do
begin
statement;
statement { Semicolon optional for last statement in block }
end;
for i := 1 to 5 do
writeln(i);
for i := 5 downto 1 do
writeln(i);
Usage
- break; : Break from a for, while, or repeat statement.
- continue; : Continue with the next iteration of a for, while, or repeat statement.