Computer Science Canada

Nested Loops

Author:  ScaryRat [ Fri Aug 06, 2010 2:03 pm ]
Post subject:  Nested Loops

//loop 1
while (stuff) {

//loop 2
while (other stuff) {

}
code
}

Assume that "stuff" and "other stuff" are true.
In order for "code" to be ran, does "other stuff" have to be false (thus ending loop 2)?

Author:  chrisbrown [ Fri Aug 06, 2010 2:18 pm ]
Post subject:  RE:Nested Loops

Correct.

Author:  jbking [ Fri Aug 06, 2010 6:20 pm ]
Post subject:  Re: Nested Loops

Unless you put a break in the inner loop which would then run the "code" part you highlight. In other words, there is more than one way to get out of a while loop.

Author:  LeeShane [ Wed Nov 17, 2010 3:36 am ]
Post subject:  RE:Nested Loops

see Loop goes to run until "stuff" or "other stuff" is true. you have to make it false if want to quit loop.
Both are in infinite loop


: