Thread: Break statement
View Single Post
Old May 21st, 2006, 7:28 PM   #1
Eric the Red
Hobbyist Programmer
 
Eric the Red's Avatar
 
Join Date: Feb 2006
Posts: 214
Rep Power: 0 Eric the Red is an unknown quantity at this point
Break statement

Does anyone know how to break out of a double loop?

I understand that by using "break;" you can jump out of a loop. But what happens when i'm running through a 2-d array and i want to break out of a double loop? Is there any simple way like "break, break;" or "break 2x" LOL?
I could assign a boolean variable "true" then test whether it is true in the outer loop.

example:

                            for (y= 0; y < 10;y++)
                            {
                              for (x = 0; x < 10; x++)
                              {
                                 if (arrayTwoDimension[x][y].getState = true)
                                 {
                                    blnBreak = true;
                                    break;
                                  }
                              }
                              if (blnBreak = true)  // tedious
                                  break;
                            }

Note the test in the 'y loop' (blnBreak = true).

Anyone know a quick fix for this problem? What should I be doing in this situation?
__________________
Death smiles at us all. All a man can do is smile back.
Eric the Red is offline   Reply With Quote