next up previous contents
Next: Comments Up: Compound statements Previous: Loops   Contents

Goto

There is no goto in Java. However, the language has labelled break statements that allow several levels of nested loops to be terminated in one go. For example:

 outer_loop:                // this is a loop label
  for (i = 0; i < n; i++){
    for (j = 0; j < n; j++){
      if (a[i][j] == k){
         break outer_loop;  // exits the outer for loop
      }
    }
  }



Madhavan Mukund 2004-04-29