Forum > Documentation (Maintaining -)

Unclear repeat-until docs

<< < (2/3) > >>

eny:

--- Quote from: Blaazen on November 19, 2020, 03:24:19 am ---https://wiki.freepascal.org/REPEAT..UNTIL

--- Quote ---Also, the loop continues until the Boolean expression is TRUE, whereas the while loop continues until the Boolean expression is FALSE.
--- End quote ---
This can be understood wrongly.  ;D

--- End quote ---
The writer probably wrote it just after the while... page and it probably was end of the day.
The reference to the while loop here does not add to the explanation.
And the page could do with an example or 2 (as was done on the while... page).

It's also not the case that some magic thing called 'a loop' is doing something.
It's just that the (compound) statement is executed repeatedly as long as or until a certain condition is met.

lucamar:
Maybe a mention to (deliberately) infinite loops and why they work could be added, if just for newbies's sake. something along the lines of:

--- Quote ---The loop continues until the Boolean expression is TRUE, which is why a loop of the form:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---repeat  ...until False;will never stop unless there is a Break or GoTo inside it, maybe based on some condition. (add some example)
--- End quote ---

and similar text in the "while" section.

Better redacted, of course :-[


--- Quote from: eny on November 19, 2020, 04:33:00 pm ---The reference to the while loop here does not add to the explanation.
--- End quote ---

My guess is that it was added because the differences between repeat and while loops often confuses beginners and has become a FAQ.

Sieben:
Important differences between while and repeat loops that should be pointed out are

a) that the latter will always be entered at least once whereas the former isn't necessarily

and

b) that the condition to leave a repeat loop will have to be coded as a negation to the very same condition to leave a while loop:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---while Assigned(Node) do...end;
which is not entered at all if Node is nil

versus


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---repeat...until not Assigned(Node);
which is entered in any case.

winni:
Hi!

Siebens addition is important.

While is the defensive way.
Repeat ... until  should only be used if the value of a var is unknow.
Example is user input.
Or findFirst/findNext/findClose.

If I look in different code it seems that while gets out of "fashion":

We start with for or repeat   and the rest ist done with a break or an exit.

That's bad style. It says that you did not think about the problem, before you hacked into your keyboard.

Winni


PascalDragon:
Feel free to report a bug to get the documentation improved.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version