Author Topic: Maybe a misunderstanding about the use of "exit for", or not.  (Read 3943 times)

0 Members and 1 Guest are viewing this topic.

Offline doppler

  • Forum Regular
  • Posts: 241
    • View Profile
Came upon a strange can't do that in the IDE.  See below the pointless program:

for x=1 to 10
   print x,;
     for y=1 to 2
       if x=6 then exit for
          print y,;
     next y
  print
next x

This pointless program if it could be entered, would print nine groups of x count, with y counts in between.  Except when x is equal to 6.

My expectation would be the last setup "for" command, would follow the "exit for". And exit at the print between the two next's.  Very much like push and pop assembler commands.

I had a use for a lot of nested "for setups", which needed conditional nested exit's.  This example is a pointless program.  Don't need a fix for it.  Just wanted to know if it's a real bug or not in the IDE, or Qb64.

Sorry I come up with strange uses for QB64.  But then only QB64 will do it.

Thanks

FellippeHeitor

  • Guest
Re: Maybe a misunderstanding about the use of "exit for", or not.
« Reply #1 on: April 04, 2018, 11:30:48 am »
The output I got:
Quote

 1   1   2
 2   1   2
 3   1   2
 4   1   2
 5   1   2
 6
 7   1   2
 8   1   2
 9   1   2
 10  1   2

I believe I don't understand your report. The program works exactly as expected (see attached screenshot). Are you saying the IDE didn't compile it? Or that you were expecting a different output from what I got?

If you didn't want the "6" printed, you'd have to evaluate IF x = 6 in another spot:

for x=1 to 10
   if x=6 then _CONTINUE
   print x,;
     for y=1 to 2
          print y,;
     next y
  print
next x
« Last Edit: April 04, 2018, 11:32:35 am by FellippeHeitor »

Offline doppler

  • Forum Regular
  • Posts: 241
    • View Profile
Re: Maybe a misunderstanding about the use of "exit for", or not.
« Reply #2 on: April 04, 2018, 11:47:14 am »
Now this makes no sense too.  This was just a stupid example which I did not try.  The only difference is my other nested "for"s where inside a large do/loop. And that should make not a difference.  As I think about it, the exit command does a whole lot of different things depending on how you want to exit.  re: exit do, exit for, exit etc......

I will think of a smarter stupid example, and get back to you.

Ha, smarter stupid example, aka, large shrimp