Examples and operator structure
Typical examples of WHILE cycle, available in "COMPAS" are the following:
- WHILE s[i] <> ' ' DO i := i + 1;
- WHILE a < 10 DO BEGIN s := s + a; a := a + 1 END;
- WHILE b DO BEGIN w := w-1; b := w=0 END;
Possible structures of this operator can be written the following way:
WHILE {condition} DO {operator} ;
WHILE {BOOLEAN variable} DO {operator} ;
Note, that instead of {operator} several operators,
confined between reserved words BEGIN and END - so called
compound statement - can be used.
If we compare the short variant of IF (left) with WHILE operator (right),
we should see, that they look very similar:

The only difference is jump to the beginning of the cycle in the second case.
So it's no wonder, that the realization of these structures are similar enough too.
Back to: