Author Topic: An improved FOR NEXT loop  (Read 6599 times)

0 Members and 1 Guest are viewing this topic.

Offline zaadstra

  • Newbie
  • Posts: 78
    • View Profile
Re: An improved FOR NEXT loop
« Reply #30 on: July 12, 2021, 04:46:07 pm »
I'm probably missing the point here ;-)  FOR NEXT is perfectly working fine if you know the rules.

I want to add my 'special' that I'm using sometimes in FOR NEXT.

Code: QB64: [Select]
  1. FOR i=1 TO 10
  2.  ' code
  3.    IF condition = TRUE then i=11 ' cleanly jump out of loop at end
  4.  ' even more code

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: An improved FOR NEXT loop
« Reply #31 on: July 12, 2021, 05:08:54 pm »
@bartok
about
Quote
the DO-LOOP cycle, not only often exites with EXIT DO without reaching the condition of LOOP UNTIL, LOOP WHILE, DO UNTIL, DO WHILE, but it can also loops only a part of itself. FOR-NEXT, it is very powerfull to make arrays for math purposes.
you can  evaluate this new opportunity that is of QB64 and not of Qbasic
http://qb64.org/wiki/CONTINUE together  this one http://qb64.org/wiki/EXIT


@zaadstra
about exiting from FOR loop
your tip is good in QB45, but your code becomes this following one in QB64
Code: QB64: [Select]
  1. FOR i=1 TO 10
  2.  ' code
  3.  ' even more code
  4.   IF condition = TRUE then EXIT  FOR   'i=11 ' cleanly jump out of loop at end

Programming isn't difficult, only it's  consuming time and coffee

Offline bartok

  • Newbie
  • Posts: 80
    • View Profile
Re: An improved FOR NEXT loop
« Reply #32 on: July 13, 2021, 02:57:45 am »
@bartok
about you can  evaluate this new opportunity that is of QB64 and not of Qbasic
http://qb64.org/wiki/CONTINUE together  this one http://qb64.org/wiki/EXIT

Very interesting. I have to try, but I think it can remove the necessity of DO-LOOPs nested in pairs. Thank's.
« Last Edit: July 13, 2021, 03:06:37 am by bartok »

Offline bartok

  • Newbie
  • Posts: 80
    • View Profile
Re: An improved FOR NEXT loop
« Reply #33 on: July 13, 2021, 03:16:57 am »
No, nothing changes in my case: DO-LOOPs nested in pairs must stay in place, because, generally, when some definite variables become TRUE in the second level, the DO-LOOP exites with EXIT DO, and the program goes to the DO-LOOP of first level, but here not necessary the program must loop the pair: here an other control of the variables determines if the program has to loop the pair, or exit and go to the second level of an other pair of DO-LOOP, and so on until the program ends or the user want to close it. _CONTINUE doesn't allow the described check of variables, but it is a useful command.
« Last Edit: July 13, 2021, 03:18:59 am by bartok »