Forums Register Login

labelled break

+Pie Number of slices to send: Send
Hi, I have a question about labelled break.
mainloop: for(int i = 0; i < array.length; i++){
for(int j = 0; j < array[i].length; j++){
if(array[i].secondArray[j]=='\u0000'){
break mainlooop;
}
}
}
does the flow of the program leaves the "j for loop" and go to the "i for loop" with i incremented? If that is the case, what's the difference between a labelled continue and a labelled break?

mainloop: for(int i = 0; i < array.length; i++){
for(int j = 0; j < array[i].length; j++){
if(array[i].secondArray[j]=='\u0000'){
continue mainlooop;
}
}
}
+Pie Number of slices to send: Send
A break with a label breaks the entire loop. So it breaks out of the i and j loop. continue label; begins in the mainloop again:

[This message has been edited by Mathias P.W Nilsson (edited August 18, 2001).]
+Pie Number of slices to send: Send
Then do it starts with i==0, all over again? Or just ++i like continue?
+Pie Number of slices to send: Send
Hi, I really need to know this. Somebody please help?
+Pie Number of slices to send: Send
Hi Cameron,
Just I have changed Nilsson's code little bit and executed,
go thru this code and its output
code 1:



The output is
j: 0 i: 0
j: 1 i: 0
breaking mainloop

If you replace break mainloop with continue mainloop the output will be like this
j: 0 i: 0
j: 1 i: 0
continuing mainloop
j: 0 i: 1
j: 1 i: 1
continuing mainloop
j: 0 i: 2
j: 1 i: 2
continuing mainloop

Hope this helps
Indu

+Pie Number of slices to send: Send
break label works like this:
here:
for (;
for (;
break here; //line A
//line B
when program reach line A, it will first go to "here: " and then go the line B.. (skip things in between). Try to put "continue here;" instead of "break here;" and u will enter an infinite loop! haha
Oh the stink of it! Smell my tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 894 times.
Similar Threads
multi dimensional arrays
Can someone please explain the following code to me...
return,continue,break keywords
labelled break
how to while loop with the condition being multiple elements of an array?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 11:27:43.