Nested loops
 

Nested loops are where you have loops inside each other. Obviously this is very useful ;) The only thing you really need to remember is that the the whole of the inner loop must be on the inside of the outer loop. In other words you cannot do things like this:
Start outer loop
Start inner loop
End outer loop
End inner loop

An example of some correctly nested loops:

Code ; You can see that the inner loop is repeated every time round the outer loop
For i.w=0 To 10
For j.w=0 To 10
NPrint "i=",i," j=",j
Next
Next

; Of course, you can nest any kind of loops, and have as many levels of nesting as you like
; (as long as you stick by the rule that loops must be entirely inside each other)
i = 0
Repeat

j = 10
While j > 0
If i < j
Select j-i
Case 1
NPrint "Well, that's about as close as they can get :)"
Case 2
NPrint "Oooh, getting closer"
Case 3
NPrint "Things starting to heat up now"
Default
NPrint "Don't make me laugh foo!"
End Select
EndIf
j+1
Wend
i+1
Until i=10
MouseWait
End


Previous: Repeat...Until loops Programming contents Next: Exiting loops early


News | Introduction | Search | List/Forum/IRC Webring | Contact
Installation | Troubleshooting | Programming | Archives | Links
Return to programming main
Page last modified: 17th March 2002