Difference between revisions of "Loops"
(more precise definition) |
m (→types: syntax) |
||
Line 14: | Line 14: | ||
== types == | == types == | ||
[[Standard Pascal|Pascal]] defines | [[Standard Pascal|Pascal]] defines | ||
− | * counting loops [[For|<syntaxhighlight lang="pascal" inline | + | * counting loops [[For|<syntaxhighlight lang="pascal" inline>for … to|downto do</syntaxhighlight>]] |
* conditional loops | * conditional loops | ||
− | ** [[While|<syntaxhighlight lang="pascal" inline | + | ** [[While|<syntaxhighlight lang="pascal" inline>while … do</syntaxhighlight>]], and |
− | ** [[Repeat|<syntaxhighlight lang="pascal" inline | + | ** [[Repeat|<syntaxhighlight lang="pascal" inline>repeat … until</syntaxhighlight>]] where the loop head appears at the foot. |
− | The [[FPC]] also supports [[for-in loop|<syntaxhighlight lang="pascal" inline | + | The [[FPC]] also supports [[for-in loop|<syntaxhighlight lang="pascal" inline>for … in … do</syntaxhighlight>]] loops. |
== comparative remark == | == comparative remark == |
Revision as of 20:46, 20 August 2020
│ Deutsch (de) │ English (en) │
A loop control structure repeats a statement as long as a certain condition is met.
properties
A loop is sectioned into a
- loop head, and a
- loop body.
The loop body is a statement, and the head contains a Boolean expression that determines whether the loop body is executed (again).
Loops are particularly useful as a programming construct, since the loop body is only inserted once in the final program. The so-called “loop unrolling” optimization may copy the loop body multiple times anyway, but still you do not need to literally repeat the statements in your source code.
types
Pascal defines
- counting loops
for … to|downto do
- conditional loops
while … do
, andrepeat … until
where the loop head appears at the foot.
The FPC also supports for … in … do
loops.
comparative remark
Unlike in some programming languages, in Pascal a loop itself is a statement; it does not yield a value.