Statements


The MIDletPascal statement can be any of the following:

For loop

for loop has the following sytax:

for loopIndex := initialValueExpression to finalValueExpression do
begin
  statements
end;

Instead of keyword to, keyword downto can be used to indicate that the loopIndex will be decreased by one in each loop iteration.

The following code block will calculate the sum of the numbers 1 to 10:

  ...
  for i:= 1 to 10 do
  begin
    sum := sum + i;
  end;
  ...

If there is only one statement within the loop, begin and end keywords may be omitted.

While loop

the loop has the following syntax:

while condition do
begin   statements
end;

For example, to wait for the user input we could write:

  ...
  while (getKeyClicked = KE_NONE) do
  begin
    delay(100);
  end;
  ...

If there is only one statement within the loop, begin and end keywords may be omitted.

Repeat-until loop

repeat until loop has the following syntax:

repeat
  statements;
until endingCondition;

To wait until the user presses the key, we could write:

  ...
  repeat
    delay(100);
    until (getKeyClicked <> KE_NONE);
  ...

Break statement

The break statement is used to exit from the innermost for, while or repeat loop.

  ...
  repeat
    for i := 1 to 10 do
    begin
      if doSomething(i) = -1 then break; // break from for-loop
    end;

  until getClickedCommand <> emptyCommand;
  ...

If-then-else statement

If-then-else statement has the following sytax:

if condition then
begin
  statements; { condition true branch }
end
[
else
begin
  statements; { condition false branch }
end;
]

The else branch may be omitted. If there is only one statement inside the branch, begin and end keywords may be omitted.

Assignment operator

Assignment operator is used to assign values to variables and has the following syntax:

variable := value;

Value can be an expression, variable, function call or constant.