0
Nested Loop Break
How can we break a loop directly from another nested loop? e.g: for(int i=0;;i++){ for(int j=0;;j++){ if(matrix[i][j]==100){ break break; //exit both loops } else if(j==10){ break; } } }
15 odpowiedzi
+ 4
Nested Loop Break
How can we break a loop directly from another nested loop? e.g:
for(int i=0;;i++){
for(int j=0;;j++){
if(matrix[i][j]==100){
goto break_pt; //exit both loops
}
else if(j==10){
break;
}
}
}
break_pt:
+ 5
You can use a goto, not pretty but it works.
+ 4
yes.
+ 4
visph, you should talk about being rude, you (or it was you I suspect) downvoted my reply (without trying to prove your point) because I said some things about C++ that it does better than Python :P
+ 3
visph- I was not even talking to you anyway so why downvote it? Saphirre said that C++ was "bare bones" which is totally not true and shows a lack of knowledge about the language.
+ 2
@Karl T.:
Are you talking of this thread: https://www.sololearn.com/Discuss/520618/?ref=app ?
Yes, I have downvoted your post, to mark my disagree, not because you said that C++ does better than Python, but because you said << Some say that C++ is more bare bones, but that is just because they don't know or are not aware of libraries that are available >> and that's absolutly not why I consider Python more easiest than Python but not better than it ^^
Voting system have lot of bad sides, and is frequently missused (likestorms, bad/innacurate/unrelated answers upvoted just because following someone), but it exist so should be used and I try tp do it with most honestly as possible ;)
+ 1
only use of goto or return will exit all nested fors
+ 1
@Andres Eduardo Goncalves:
It's not related to this question but to your last one that you have immediatly deleted after receiving my answer pointing your mistakes...
This way of doing is irespectuous of answerers which take time to study your code, fix it and elaborate accurate information about them ^^
Next time I will spare my time and not spend it for you :P
+ 1
@Andres wrote: << Sorry man I clicked delete accidentally :/ >>
Sure, you clicked on question context menu "accidentally", and then again clicked "accidentally" the 'delete' option inside it @@
+ 1
If somebody don't like any code or post can downvote it, votes are made for that, if you like it, upvote it, if not, downvote it...
But... Before vote you need arguments to upvote or downvote...
0
I know we can do:
for(bool x=true, int i=0;x;i++{
for(int j=0;x;j++){
if(matrix[i][j]==100) x=false;
}
}
But... Is there another keyword or function to do that?
0
Is it possible to 'goto' a point defined after the goto statement?
0
...
goto point;
...
point:
...???
0
Sorry man I clicked delete accidentally :/
0
I was editing the question