preview

Pt1420 Unit 6 Ipl

Satisfactory Essays

Basically a break statement is used to exit the current executing loop, only the inner most loop is terminated. For example look at the following code While (true) {//A While (true) {//B break; } } The above results in a forever loop since the break statement exists from the inner most loop B.To avoid such condition java has the feature named as “named breaks”. In named break each loop is labelled with some name for example look at the following code below A: while (true) { B: while (true) { break A; } } The above code will not result in a forever loop.since it breaks out of the loop as is mentioned.this feature isn’t available in c and c++ instead they use the goto statement to come out of the loop lets see an example

Get Access