Author Topic: Question about for .. next  (Read 2056 times)

0 Members and 1 Guest are viewing this topic.

Arnold

  • Guest
Question about for .. next
« on: March 07, 2015, 04:30:15 AM »
Hi Charles,

in Oxygenbasic I can use exit for leaving a do while block. Obviously I can use goto in a for loop, for example:

Code: OxygenBasic
  1. 'Exit for .. next loop
  2.  
  3. include "$\inc\console.inc"
  4.  
  5. dim array[100]
  6.  
  7. for z = 1 to 3
  8. for y = 1 to 10
  9. For x=1 to 100
  10.   if x = 55 then goto 1200
  11.   array(x)=x
  12. next x
  13.  
  14. 1200: print x " "
  15. if y = 5 then print cr: goto 1500
  16. next y : print cr
  17.  
  18. 1500: print y cr
  19. for n = 1 to 100: print array[n] " ": next : print cr
  20. next z : print cr
  21.  
  22. print x " " y " " z cr
  23.  
  24. waitkey()
  25.  

this gives the expected results, I only would like to ask if this method is proper or if I should use a different approach? I also tried to jump into another 'for next' loop, but this happily did not work.


Roland


.

Aurel

  • Guest
Re: Question about for .. next
« Reply #1 on: March 07, 2015, 07:13:12 AM »
you can use exit for

Charles Pegge

  • Guest
Re: Question about for .. next
« Reply #2 on: March 07, 2015, 07:16:42 AM »
Hi Roland,

You can jump from an inner block to an outer block but not vice versa. This is because inner block labels are not visible to outer blocks, and when a block finishes, its inner labels are forgotten.

There is no problem jumping out of loops , using exit or goto or jmp / jmp fwd