That would not be readable.
I agree.... Just pointed out the possibility.
Its basically the: assignment and condition in one....
But what you really want is something that:
- Ideally makes it clear what variable is your loop var. Maybe even protects it, like for does
- Has a clear "loop condition" (rather than zero, one or more "break" conditions somewhere buried in the middle of the loop code)
- has an initial value for the loop var
- has an update for the loop var
=> Or in your case initial and update is the same.
Even the "for(initial, condition, update)" does not fulfil that
In other words, the conflict you have is IMHO that:
- You need the loop condition in the middle (after getting the random number, but before printing it)
- You want the loop condition to be clearly noticeable, which means it should be part of the loop statement (no infinite loop statement)
Those 2 statements directly contradict each other.
So the problem is logical at first, rather than just missing syntax....
- Init goes before the loop
- update goes into the loop
If both are combined, where should they go?
If you ignore the fact that in your case "init loop var" and "update loop var" is the same. And therefore leads to syntactical duplication (the meaning is not duplicated), then you should end up with an earlier proposal:
init;
while cond do begin
work
update
end
or
a := random(101); // init
while a <= 75 do begin
writeln(a); // work
a := random(101); // update => different meaning, even if same text
end;
Or (not what I would do...)
goto loopstart;
while a <= 75 do begin
writeln(a);
loopstart:
a := random(101);
end;