ExitFor
ExitFor <.LoopCounter.>
 
Parameters:

    <.LoopCounter.> = The For/Next loop counter to break out of
Returns: NONE
 

      ExitFor will force PlayBASIC to break out of the current For-Next loop that is being executed. It can also be used to break out a nested for-next statement, by using the 'loop-counter' of the for-next you wish to exit



FACTS:


      * Only works within For-Next loops.

      * When an ExitFor command is executed, PlayBASIC will continue the program code following the Next statement.




Mini Tutorial #1:


Breaking free of For-Next when a condition is met.

  
; a simple For-Next loop
  For i = 1 To 100
     Print i
   ; Exit the For-Next loop if i equals 9
     If i = 9 Then ExitFor
  Next i
  Print "This program has ended.."
  
; display the screen and wait for a key to be pressed
  Sync
  WaitKey
  
  



This example would output.

  
  1
  2
  3
  4
  5
  6
  7
  8
  9
  This program has ended..
  





Mini Tutorial #2:


Breaking free of Nested For-Next when a condition is met.

  
; a simple For-Next loop
  For Count=0 To 100000
   ; a nested For-Next loop
     For i = 1 To 100
        Print i
      ; Exit the OUTTER For-Next loop if i equals 9
        If i = 9 Then ExitFor Count
     Next i
  Next Count
  
  Print "This program has ended.."
  Print Count
  Print i
  
; display the screen and wait for a key press
  Sync
  WaitKey
  


This example would output.

  
  1
  2
  3
  4
  5
  6
  7
  8
  9
  This program has ended..
  0
  9
  



 
Related Info: Continue | Do | Exit | For | Goto | Next | Repeat | While :
 


(c) Copyright 2002 - 2024 - Kevin Picone - PlayBASIC.com