Recent

Author Topic: Unclear repeat-until docs  (Read 3861 times)

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Unclear repeat-until docs
« 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
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. ;

Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Unclear repeat-until docs
« Reply #1 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
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: Unclear repeat-until docs
« Reply #2 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
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.

Zoran

  • Hero Member
  • *****
  • Posts: 1829
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: Unclear repeat-until docs
« Reply #3 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
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.

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: Unclear repeat-until docs
« Reply #4 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.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

eny

  • Hero Member
  • *****
  • Posts: 1634
Re: Unclear repeat-until docs
« Reply #5 on: November 19, 2020, 04:33:00 pm »
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.
All posts based on: Win10 (Win64); Lazarus 2.0.10 'stable' (x64) unless specified otherwise...

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Unclear repeat-until docs
« Reply #6 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.
« Last Edit: November 19, 2020, 11:15:06 pm by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

Sieben

  • Sr. Member
  • ****
  • Posts: 310
Re: Unclear repeat-until docs
« Reply #7 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.
« Last Edit: November 19, 2020, 11:59:35 pm by Sieben »
Lazarus 2.2.0, FPC 3.2.2, .deb install on Ubuntu Xenial 32 / Gtk2 / Unity7

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: Unclear repeat-until docs
« Reply #8 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



PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: Unclear repeat-until docs
« Reply #9 on: November 20, 2020, 03:38:11 pm »
Feel free to report a bug to get the documentation improved.

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: Unclear repeat-until docs
« Reply #10 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).
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

eny

  • Hero Member
  • *****
  • Posts: 1634
Re: Unclear repeat-until docs
« Reply #11 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.

All posts based on: Win10 (Win64); Lazarus 2.0.10 'stable' (x64) unless specified otherwise...

Kays

  • Hero Member
  • *****
  • Posts: 569
  • Whasup!?
    • KaiBurghardt.de
Re: Unclear repeat-until docs
« Reply #12 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.

The great thing about wikis is that everyone who’s authorized can edit it, as HowardPC just did. 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 with the already existing article Loops.

Note, AFAIK the article For has been correct since, pretty much always, and I even added an extra note on inclusive loop limits in the article For over two years ago. I guess/hope most people will go there if they’re looking for for-loops.
Yours Sincerely
Kai Burghardt

eny

  • Hero Member
  • *****
  • Posts: 1634
Re: Unclear repeat-until docs
« Reply #13 on: November 20, 2020, 10:28:59 pm »
Note, AFAIK the article 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;
All posts based on: Win10 (Win64); Lazarus 2.0.10 'stable' (x64) unless specified otherwise...

PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: Unclear repeat-until docs
« Reply #14 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.

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

 

TinyPortal © 2005-2018