Lazarus

Miscellaneous => Documentation (Maintaining -) => Topic started by: Blaazen on November 19, 2020, 03:24:19 am

Title: Unclear repeat-until docs
Post by: Blaazen on November 19, 2020, 03:24:19 am
Hi, I noticed that text on this page is not very clear (but maybe it is my english).
https://wiki.freepascal.org/REPEAT..UNTIL (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.
This can be understood wrongly.  ;D

Endless loops are
Code: Pascal  [Select][+][-]
  1. repeat
  2. until False;
  3.  
  4. while True do
  5. ;

Title: Re: Unclear repeat-until docs
Post by: lucamar on November 19, 2020, 07:17:41 am
Sounds like a conundrum but if you think logically about it you'll see that the text is indeed right: repeat will keep looping until the condition (False) becomes True, whereas while will keep running until the condition (True) becomes False. Neither of which will ever pass (barring a "cosmic rays" incident ;)), so "infinite" loops.

Computer languages are funny like that :D
Title: Re: Unclear repeat-until docs
Post by: PascalDragon on November 19, 2020, 09:15:48 am
Hi, I noticed that text on this page is not very clear (but maybe it is my english).
https://wiki.freepascal.org/REPEAT..UNTIL (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.
This can be understood wrongly.  ;D

In how far can this be understood wrongly?

Endless loops are
Code: Pascal  [Select][+][-]
  1. repeat
  2. until False;
  3.  
  4. while True do
  5. ;

Yes, they are and they're supposed to be.
Title: Re: Unclear repeat-until docs
Post by: Zoran on November 19, 2020, 11:15:17 am
Hi, I noticed that text on this page is not very clear (but maybe it is my english).
https://wiki.freepascal.org/REPEAT..UNTIL (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.
This can be understood wrongly.  ;D

I really cannot see anything confusing there. Quite clearly it says that:

Repeat-until loop continues while the expression is false and UNTIL it becomes true,
whereas
while loop continues WHILE the expression is true and until it becomes false.
Title: Re: Unclear repeat-until docs
Post by: Blaazen on November 19, 2020, 04:08:38 pm
So it rather seems my english is not perfect.
Quote
Also, the loop continues until the Boolean expression is TRUE = Also, the loop stops when the Boolean expression is TRUE
and
Quote
while loop continues until the Boolean expression is FALSE =  while loop stops whenl the Boolean expression is FALSE
It was simply a little unclear to me.
Title: Re: Unclear repeat-until docs
Post by: eny on November 19, 2020, 04:33:00 pm
https://wiki.freepascal.org/REPEAT..UNTIL (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.
This can be understood wrongly.  ;D
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.
Title: Re: Unclear repeat-until docs
Post by: lucamar on November 19, 2020, 11:10:39 pm
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  [Select][+][-]
  1. repeat
  2.   ...
  3. until False;
will never stop unless there is a Break or GoTo inside it, maybe based on some condition. (add some example)

and similar text in the "while" section.

Better redacted, of course :-[

The reference to the while loop here does not add to the explanation.

My guess is that it was added because the differences between repeat and while loops often confuses beginners and has become a FAQ.
Title: Re: Unclear repeat-until docs
Post by: Sieben on November 19, 2020, 11:49:43 pm
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  [Select][+][-]
  1. while Assigned(Node) do
  2. ...
  3. end;

which is not entered at all if Node is nil

versus

Code: Pascal  [Select][+][-]
  1. repeat
  2. ...
  3. until not Assigned(Node);

which is entered in any case.
Title: Re: Unclear repeat-until docs
Post by: winni on November 20, 2020, 12:47:06 am
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


Title: Re: Unclear repeat-until docs
Post by: PascalDragon on November 20, 2020, 03:38:11 pm
Feel free to report a bug to get the documentation improved.
Title: Re: Unclear repeat-until docs
Post by: Blaazen on November 20, 2020, 04:13:45 pm
And a note: there are four languages. The chinese one has example, the others don't. Also, I think such docs should - at best - be written by native speakers. Here the author looks like someone from east Asia (but of course it's only my guess).
Title: Re: Unclear repeat-until docs
Post by: eny on November 20, 2020, 09:00:44 pm
Unfortunately there are actual errors in that informal Pascal introduction. According to that text
In the for-to-do loop, the starting value MUST be lower than the ending value, or the loop will never execute!
This is obviously not correct.

This error is quite persistent because it also is made here: https://wiki.freepascal.org/loop_instruction.

Title: Re: Unclear repeat-until docs
Post by: Kays on November 20, 2020, 10:05:29 pm
Feel free to report a bug to get the documentation improved.
Uhm, as far as I understand the complaint’s about the Tao Yue’s Object Pascal tutorial page(s) in the wiki. I don’t think you are supposed to file bug reports for mistakes in the wiki, only if it’s about Michaël Van Canneyt’s documentation (https://freepascal.org/docs.html).

The great thing about wikis is that everyone who’s authorized can edit it, as HowardPC just did (https://wiki.freepascal.org/index.php?title=REPEAT..UNTIL&curid=4030&diff=141155&oldid=131129). You just need to create an account. No extra vetting/approval necessary.

Unfortunately there are actual errors in that informal Pascal introduction. According to that text
In the for-to-do loop, the starting value MUST be lower than the ending value, or the loop will never execute!
This is obviously not correct.

This error is quite persistent because it also is made here: https://wiki.freepascal.org/loop_instruction
This article is a fairly recent creation. I’ve already suggested to the original author to merge it (https://wiki.freepascal.org/index.php?title=User_talk:Rfc1394&oldid=141112#loop_instruction) with the already existing article Loops (https://wiki.freepascal.org/Loops).

Note, AFAIK the article For (https://wiki.freepascal.org/For) has been correct since, pretty much always, and I (https://wiki.freepascal.org/index.php?title=For&diff=116721&oldid=115878) even added an extra note on inclusive loop limits in the article For (https://wiki.freepascal.org/index.php?title=For&oldid=141113#limits) over two years ago. I guess/hope most people will go there if they’re looking for for-loops.
Title: Re: Unclear repeat-until docs
Post by: eny on November 20, 2020, 10:28:59 pm
Note, AFAIK the article For (https://wiki.freepascal.org/For) has been correct since, pretty much always,
Another page that says something about loops  :o

It seems the pages that describe loops are stuck in loop...
Code: Pascal  [Select][+][-]
  1. while true do
  2. begin
  3.   CreateNewLoopsPage;
  4.   sleep(RandomNbOfdays)
  5. end;
Title: Re: Unclear repeat-until docs
Post by: PascalDragon on November 21, 2020, 05:59:58 pm
Feel free to report a bug to get the documentation improved.
Uhm, as far as I understand the complaint’s about the Tao Yue’s Object Pascal tutorial page(s) in the wiki. I don’t think you are supposed to file bug reports for mistakes in the wiki, only if it’s about Michaël Van Canneyt’s documentation (https://freepascal.org/docs.html).

Ah, right, I thought the link went to the documentation. My bad. :-[
TinyPortal © 2005-2018