Hi!
I have show the clear solution above.
Except that this has the same error I did in my first post also, if c is 3, the loop is broken and the a loop will continue which will increase a.
Imagine the following case, inputbox always returns 3. In the goto example (which is basically what the original post did), this would result in an infinite loop, in your example this would result in exactly 11 iterations and then the procedure would finish.
Otherwise, I would choose the break version, because for loops are imho easier to read then while loops.
Also, what does "pure pascal" mean, aren't break and goto parts of the pascal language?
With nested loops, breaking out may require flags be set
if break_condition then begin brflag := true; break end;
Then use brflag to get out of the outer loop and so on. (break doesn't "break" begin/end closures, only controlled loops (while, for, repeat).
Some code I recently revised (which doesn't use break, but comes to the same thing...)
// long winded code not shown here ... but you can assume the Repeat's are there...
With P^ do
begin
Case State of
0: found := (FPStat=PartialPlay) and (Playtime<TLim);
1: found := (FPStat=NeverPlayed) and NOT TooNew and (Playtime<TLim);
2: found := (FPStat<>PlayedThisSession) and NOT TooNew and (Playtime<TLim);
3: found := (FPStat<>PlayedThisSession) and (Playtime<TLim);
4: found := Playtime<TLim;
5: found := true; // unlikely but need a guaranteed way out.
end;
end;
Until found or (Rc >= GC[Gr]);
Until found or (Tlim>now);
Until found;
exit(P)
END;
Loop control (For, While, Repeat) is an implementation choice for functional, efficient, readable (in that order) code.
I personally will use Repeat more than While if it makes sense ... but that isn't always the most readable code.
And for is for a strict range of choice (even if the range is defined by variables) whereas the others are for things that change state inside the loop(s).
Goto is in the original Wirth Pascal manual but should not be used.
FPC requires a {$GOTO ON} and label pre-declaration. AVOID.
Break/Continue are add ons (necessary) to the original language.