13.9.2021

Java Continue Quiz

public class JavaFiddle {
    public static void main(String[] args) {
    
    int y = 0;
    
    for (int i = 0; i < 10; i++) {
      
      try {
    	  y = i;
          throw new RuntimeException();
      } catch (RuntimeException re) {
        
        System.out.println("Continuing for y = " + y);
        continue;
      }
    
    }  
    
    System.out.println(y);
  }
}

a)

Continuing for y = 0
0

b)

Continuing for y = 0
Continuing for y = 1
Continuing for y = 2
...
9

c)

some weird RuntimeException

Lösung: Antwort b ist richtig, da das continue; hier keinen Einfluss auf den Programmablauf hat. Es könnte genauso gut weggelassen oder außerhalb des Catch Block stehen. Für mehr Information, wie man continue nutzt wird hier genauer beschrieben: www.w3schools.com/continue

Simon

Softwareentwickler

Zur Übersicht

Standort Hannover

newcubator GmbH
Bödekerstraße 22
30161 Hannover

Standort Dortmund

newcubator GmbH
Westenhellweg 85-89
44137 Dortmund