Sorry for the simple question -
If i am in two loops and I put a break in the middle does it stop the loop it is in or does it stop all loops?
Code:for(i=0; i<10; i++) { for(j=0; j<10; j++) { if(example[i][j]>100) {break;} } }
Sorry for the simple question -
If i am in two loops and I put a break in the middle does it stop the loop it is in or does it stop all loops?
Code:for(i=0; i<10; i++) { for(j=0; j<10; j++) { if(example[i][j]>100) {break;} } }
My site to register for all my other websites!
'Clifton Bazaar'
Just the inner-most loop.
If you want to exit BOTH loops, then put the double looping into it's own function and use return. Another alternative is to use goto BUT DONT DO THAT OR ELSE I WILL KILL YOU.
Better to design your loops with the exit routes already planned...
... or similar.Code:Continue = TRUE; i = -1; J = -1; while (Continue && (i < 10)) { ++i; while (Continue && (j < 10)) { ++j; if (example [i][j] > 100) Continue = FALSE; } }
Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.
You generally don't want to do that because it forces an extra check every single time you go through your loops and adds another variable.
thanks all for the help
I remember programming in 'basic' and using GOTO, nowdays everyone threatens to kill you if you use itAnother alternative is to use goto BUT DONT DO THAT OR ELSE I WILL KILL YOU.
My site to register for all my other websites!
'Clifton Bazaar'
>>>
You generally don't want to do that because it forces an extra check every single time you go through your loops and adds another variable.
<<<
The check on a simple boolean is very fast, and I like to have my escape routes planned at the design stage, easy to modify later. The variable would be a stack variable so I don't really care about that either.
In any case, I expect the optimized code generated would be similar.
Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.
adrianxw is right. break, return (in the middle of a function), goto are similar in that they break out of a smooth flowing function. They "jump" in an assembly like way and not a high level language like way.
"You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter