Welcome! Log In Create A New Profile

Advanced

leave FOR-loop prematurely (like break)

Posted by MiellesMain 
leave FOR-loop prematurely (like break)
January 24, 2023 02:44PM
In other programming languages it is possible to use keywords like break to leave a loop. Is there a way to do this in Windev?
Marc De Swert
Re: leave FOR-loop prematurely (like break)
January 24, 2023 03:46PM
Hi MillesMain
i use this when reading some text file
when there is a reason to brak the loop use Finito

LOOP
IF sLine = EOT THEN BREAK
...
IF somethin g to quit the loop THEN
GOTO Finito
ELSE
do something
END

sLine = fReadLine(lv_FileID)

END
Finito:
fClose(lv_FileID)


greetings MArc.
Re: leave FOR-loop prematurely (like break)
January 24, 2023 04:34PM
Hi MiellesMain

Like in other langauges, the keyword in WLanguage is "BREAK"...
(See Break and Continue keywords in the help)

Cheers

Peter
Re: leave FOR-loop prematurely (like break)
January 24, 2023 05:07PM
Marc, thank you, but I prefer clean code, so in most cases GOTO would be a nogo, but with good naming it might be ok.

Peter, funny thing is that the search of the windev help is the worst I've seen in years. They don't show exact results on the first page sometimes, same for break. Thank you



Edited 2 time(s). Last edit at 01/24/2023 05:15PM by MiellesMain.
Re: leave FOR-loop prematurely (like break)
January 24, 2023 05:13PM
Hi Peter, yes! Leaving a FOR-TO or a WHILE-END loop prematurely leaves the stack filled without a chance of garbage collection. Result is like a memory leak. Even in programs with the old Microsoft BASIC Compiler one could invite desaster by leaving a loop with a 'GOTO outside' command. I don't know how WLanguage reacts because I never tried to leave a loop by GOTO - I'm using BREAK all of the time, even better is a WHILE loop and exit it with a certain condition.

Kind regards,
Guenter Predl
office@windev.at



Edited 1 time(s). Last edit at 01/26/2023 07:58AM by gpredl.
Marc De Swert
Re: leave FOR-loop prematurely (like break)
January 25, 2023 04:25PM
leave FOR-loop prematurely (like break)
you asked something like a break
what I show also works, thought you were looking for something other than a break
Re: leave FOR-loop prematurely (like break)
February 21, 2023 02:07PM
> thought you were looking for something other than a break

yeah my fault eye rolling smiley



Edited 1 time(s). Last edit at 02/21/2023 02:17PM by MiellesMain.
Author:

Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: