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; } } }

8th Jul 2017, 3:39 PM
Andrés04_ve
Andrés04_ve - avatar
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:
8th Jul 2017, 3:45 PM
Karl T.
Karl T. - avatar
+ 5
You can use a goto, not pretty but it works.
8th Jul 2017, 3:43 PM
Karl T.
Karl T. - avatar
+ 4
yes.
8th Jul 2017, 3:46 PM
Karl T.
Karl T. - avatar
+ 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
8th Jul 2017, 11:49 PM
Karl T.
Karl T. - avatar
+ 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.
9th Jul 2017, 12:12 AM
Karl T.
Karl T. - avatar
+ 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 ;)
9th Jul 2017, 12:08 AM
visph
visph - avatar
+ 1
only use of goto or return will exit all nested fors
8th Jul 2017, 3:47 PM
Evgeny Satanovsky
Evgeny Satanovsky - avatar
+ 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
8th Jul 2017, 11:24 PM
visph
visph - avatar
+ 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 @@
8th Jul 2017, 11:47 PM
visph
visph - avatar
+ 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...
9th Jul 2017, 12:16 AM
Andrés04_ve
Andrés04_ve - avatar
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?
8th Jul 2017, 3:42 PM
Andrés04_ve
Andrés04_ve - avatar
0
Is it possible to 'goto' a point defined after the goto statement?
8th Jul 2017, 3:45 PM
Andrés04_ve
Andrés04_ve - avatar
0
... goto point; ... point: ...???
8th Jul 2017, 3:45 PM
Andrés04_ve
Andrés04_ve - avatar
0
Sorry man I clicked delete accidentally :/
8th Jul 2017, 11:27 PM
Andrés04_ve
Andrés04_ve - avatar
0
I was editing the question
8th Jul 2017, 11:48 PM
Andrés04_ve
Andrés04_ve - avatar