Computer Science, asked by Sukanyayayayayayayay, 11 months ago

when are labels useful in java ??

Answers

Answered by arjun6068
1
Here is one benefit of using labels in Java:
block: { // some code if(condition) break block; // rest of code that won't be executed if condition is true }
Another usage with nested-loops:
outterLoop: for(int i = 0; i < 10; i++) { while(condition) { // some code if(someConditon) break outterLoop; // break the for-loop if(anotherConditon) break; // break the while-loop // another code } // more code }
or:
outterLoop: for(int i = 0; i < 10; i++) { while(condition) { // some code if(someConditon) continue outterLoop; // go to the next iteration of the for-loop if(anotherConditon) continue; // go to the next iteration of the while-loop // another code } // more code }

Sukanyayayayayayayay: I'm in 9th standard
arjun6068: okk
arjun6068: if u have any doubt u can. ask me sis
Sukanyayayayayayayay: sure !!
arjun6068: r u using whats app ,fb ??
Sukanyayayayayayayay: yeah !
arjun6068: wat is fb name sis??
arjun6068: gud nite sis...tc...sd:)
arjun6068: gm sis
arjun6068: gud nite sis
Similar questions