SIMPOL Documentation

while

The while statement is a very useful construction and is the primary tool for creating loops. It is very flexible since it can have a start condition, an end condition, or both start and end conditions. There is no method of breaking out of a while loop. In keeping with the basic design of SIMPOL, there is one entrance and one exit to the while loop.

[Note]Tip

SIMPOL doesn't have a for … next loop nor does it have a repeat … until loop. Instead the while … end while loop is used for these cases. The for loop is a subset of a while loop in that it automatically increments the loop variable a specified amount. Since this is just a special case of a while loop, it was not added. In a compiled language there is no advantage, even if a for loop were to have been provided, it would have compiled to the same code as a while loop. As for the repeat … until loop (or the do … while loop) that is equivalent to using the SIMPOL while with no starting condition and with an ending condition.

The basic while loop looks like this:

integer err, i

// Basic while loop (similar also to for...next loop), no ending
// condition
i = 10
while i > 0
  i = i - 1
end while

// Repeat...until style loop, no starting condition
i = 10
while
  i = i - 1
end while i == 0

// Both conditions in use, the starting condition tests the loop
// variable and the ending condition tests the error return value
i = 10
err = 0
while i > 0
  err = testfunc(i)
  i = i - 1
end while err == 0

The preceding example shows three different uses of the while loop. An important point to consider is that the ending condition following the end while keywords should be read as "end the while loop if the condition is true".

[Note]Tip

Please note that the condition must evaluate to either .true or .false.