Sign in Join
Wiki copytemporary

Continue: what changed

Revision 2 to 3. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
1-The `continue` (pseudo) [[Routine|routine]] effectively skips the remainder of the [[Loops|loop]] body for one iteration, thus jumping back (or forward) to the loop head. It is a non-standardized extension.
1+The `continue` (pseudo) [[Routine|routine]] effectively skips the remainder of the [[Loops|loop]] body for one iteration, thus jumping back (or forward) to the loop head. It is a non-standardized extension.
22
3-`Continue`, with its special meaning of terminating one iteration, can only be written _within_ loops. It is not a reserved word, therefore you _could_ use it as an [[Identifier|identifier]], but still access the special routine by writing its _fully qualified_ identifier `system.continue`. In [[Mode MacPas|`{$mode MacPas}`]] the `cycle` statement is an alias for `continue`.
3+`Continue`, with its special meaning of terminating one iteration, can only be written *within* loops. It is not a reserved word, therefore you *could* use it as an [[Identifier|identifier]], but still access the special routine by writing its *fully qualified* identifier `system.continue`. In [[Mode MacPas|{$mode MacPas}]] the `cycle` statement is an alias for `continue`.
44
55## application
66
7-The use of `continue` is usually disfavored since it “delegitimizes” the loop’s condition expression. If the number of iterations can be predicted _before_ the loop starts, it is even considered bad style to use `continue`. Instead it is highly recommended to improve the algorithm. Nevertheless, in the case of _unpredictable_ data, and thus an _unpredictable_ number of (complete) iterations, `continue` is generally acceptable.
8-```
7+The use of `continue` is usually disfavored since it “delegitimizes” the loop’s condition expression. If the number of iterations can be predicted *before* the loop starts, it is even considered bad style to use `continue`. Instead it is highly recommended to improve the algorithm. Nevertheless, in the case of *unpredictable* data, and thus an *unpredictable* number of (complete) iterations, `continue` is generally acceptable.
8+
9+``` pascal
910program continueDemo(input, output, stdErr);
10- var
11- i, sum: integer;
12- begin
13- sum := 0;
14- writeLn('Enter some positive numbers, line by line:');
15-
16- // ┌─────────────────────────────────┐
17- // ↓ next iteration: check condition │
18- while not eof do // │
19- begin // │
20- readLn(i); // │
21- // │
22- if i < 1 then // │
23- begin // │
24- writeLn('Hey! Stay positive!'); // │
25- continue; // → ────────────────────┘
26- end;
27-
28- {$push}
29- {$rangeChecks off}
30- sum := sum + i;
31- {$pop}
32- if sum < 0 then
33- begin
34- writeLn('I can’t handle that much positivity.');
35- halt(1);
36- end;
11+var
12+ i, sum: integer;
13+begin
14+ sum := 0;
15+ writeLn('Enter some positive numbers, line by line:');
16+
17+ // ┌─────────────────────────────────┐
18+ // ↓ next iteration: check condition │
19+ while not eof do // │
20+ begin // │
21+ readLn(i); // │
22+ // │
23+ if i < 1 then // │
24+ begin // │
25+ writeLn('Hey! Stay positive!'); // │
26+ continue; // → ────────────────────┘
3727 end;
3828
39- writeLn('The sum of all your positive numbers is ', sum, '.');
40- writeLn('I like that positivity.');
41- end.
29+ {$push}
30+ {$rangeChecks off}
31+ sum := sum + i;
32+ {$pop}
33+ if sum < 0 then
34+ begin
35+ writeLn('I can’t handle that much positivity.');
36+ halt(1);
37+ end;
38+ end;
39+
40+ writeLn('The sum of all your positive numbers is ', sum, '.');
41+ writeLn('I like that positivity.');
42+end.
4243```
4344
44-After and at `continue` (or `cycle` in `{$mode MacPas}`) the program jumps back, or in the case of [[Repeat|`repeat … until`]] forward, to the loop’s condition. The respective condition must be satisfied again before another iteration occurs.
45+After and at `continue` (or `cycle` in `{$mode MacPas}`) the program jumps back, or in the case of [[Repeat|repeat … until]] forward, to the loop’s condition. The respective condition must be satisfied again before another iteration occurs.
4546
46-The use of `continue` can in practice always be avoided by proper [[If|`if` statements]]. It does not increase the power of Pascal. The above _demonstration_ example would be usually written _without_ a `continue`. However, if there would be _many_ or several _nested_ `if` statements, `continue` is preferred to retain _some_ degree of readability.
47+The use of `continue` can in practice always be avoided by proper [[If|if statements]]. It does not increase the power of Pascal. The above *demonstration* example would be usually written *without* a `continue`. However, if there would be *many* or several *nested* `if` statements, `continue` is preferred to retain *some* degree of readability.
4748
4849## see also
4950
50- * [`continue`](<https://www.freepascal.org/docs-html/rtl/system/continue.html>)
51- * [[Break|`break`]]
51+- [`continue`](https://www.freepascal.org/docs-html/rtl/system/continue.html)
52+- [[Break|break]]
5253
5354---
54-*From the Free Pascal wiki, page "Continue", as the Internet Archive kept it on 2022-08-12. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*
55+*From the Free Pascal wiki, page "Continue", as it stood on 2021-07-15 after a change by Kai Burghardt, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*

Back to history