Continue and Repeat doesn't work like in manual

Everything else that doesn't fall into one of the other PB categories.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Continue and Repeat doesn't work like in manual

Post by Trond »

Code: Select all

Repeat
  i + 1
  If i = 5
    Continue
  EndIf
Until i = 5 Or i = 10
Debug i
Notice that i is 5 when the program ends. The manual says that "Continue allows to skip the end of the current iteration". If it skips the end, it should continue at the top, and i should be 10.
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

skipping the rest of the current iteration does not mean skipping the end-condition.

Code: Select all

Repeat 
  i + 1 
  If i = 5 Or i=7
    Continue 
  EndIf
  Debug "bla="+Str(i) 
Until i = 10 
Debug i
oh... and have a nice day.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

; Will skip the 'Debug 5' and go directly to the next iteration
Directly to the next iteration, doesn't mean go to the next iteration if some condition is met.
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

so maybe the expression the help has to be corrected...

but it's rather funny that a Norwegian and a German are discussing the English translation of some French Compiler-Description.....

PS:
I looked up the german help...

the example is with For/Next
well, maybe the expression is a bit irritating,
but for me it's plainly clear that a Continue within a For/Next hast to
jump to the end of the loop (and then start the next iteration),
because the increment of the counter takes places within the next.
second, if a continue fits into several loop-types (repeat/while/for),
what else could it be than a simple jump?
third, a loop has to have an end-condition, so what else than skipping the
end of the iteration by jumping to the end-condition would make sense...?

PPS:

Code: Select all

...go directly to the next iteration 
has to test if there should be a next iteration or not, thus it has to pass the end-condition.
oh... and have a nice day.
AND51
Addict
Addict
Posts: 1040
Joined: Sun Oct 15, 2006 8:56 pm
Location: Germany
Contact:

Post by AND51 »

Kaeru Gaman wrote:skipping the rest of the current iteration does not mean skipping the end-condition.

Code: Select all

Repeat 
  i + 1 
  If i = 5 Or i=7
    Continue 
  EndIf
  Debug "bla="+Str(i) 
Until i = 10 
Debug i
No, CONTINUE directly jumps back to the beginning of a loop. So the code I quoted works fine.
PB 4.30

Code: Select all

onErrorGoto(?Fred)
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

AND51 wrote:No, CONTINUE directly jumps back to the beginning of a loop...
no, it just don't, and i have stated more than one reason why.

otherwise, Tronds code would have worked as he assumed, wouldn't it?

Code: Select all

Repeat 
  i + 1 
  If i = 5 
    Continue 
  EndIf 
Until i = 5 Or i = 10 
Debug i
PS:
compare with this code, this really jumps back to the beginning.

Code: Select all

Repeat
begin: 
  i + 1 
  If i = 5 
    Goto begin 
  EndIf 
Until i = 5 Or i = 10 
Debug i
oh... and have a nice day.
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

Well explained, Kaeru.

I think the manual explains it well, but the understanding is a little bit ambiguous, that's all with this issue, Trond.
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

For, While is a HeadLoop, it's jump to Head (For, While)
Repeat is a FootLoop, it's jump to Foot (Until)
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
Post Reply