LABELS

LABELS (RÓTULOS) PODEM SER USADOS PARA PULAR PARA UM LUGAR DE FORMA CONTROLADA

EXEMPLO: FAZER ALGO A UM ELEMENTO DE UMA MATRIZ RETANGULAR COM VALOR DADO (O ALVO)


class xpto {
   private float[][] matriz;

   public boolean processaAlvo( float alvo ) {
      int y, x;
      boolean achou = false;

    pesquisa:
      for( y = 0; y < matriz.length; y++ ) {
         for( x = 0; x < matriz[y].length; x++ ) {
            if( matriz[y][x] == alvo ) {
               achou = true;
               break pesquisa;
            }
         }
      }
      if( ! achou ) {
         return false;
      }

      // processa o alvo em matriz[y][x] de alguma forma
      return true;
   }
}

JAVA NÃO TEM GOTO

O GOTO EM OUTRAS LINGUAGENS É USADO PARA:

JAVA-25 home programa anterior próxima