Labels, continue und break

Switch-Anweisungen
This commit is contained in:
2019-10-31 21:40:50 +01:00
parent 526d2897d1
commit 74a2dd6e9d
4 changed files with 168 additions and 0 deletions

View File

@@ -0,0 +1,7 @@
package org.eidecker.oca8lernen.general;
public class EnumSyntax {
// Todo SeEi
}

View File

@@ -0,0 +1,7 @@
package org.eidecker.oca8lernen.general;
public class ExceptionHierarchy {
// Todo SeEi
}

View File

@@ -0,0 +1,101 @@
package org.eidecker.oca8lernen.general;
import com.sun.xml.internal.ws.api.model.wsdl.WSDLOutput;
import org.junit.jupiter.api.Test;
public class LabelContinueUndBreak {
private String i;
// Todo SeEi
@Test
public void testContinue() {
int i = 1;
while(i < 5) {
System.out.println("while" + i);
i++;
continue;
}
int j = 1;
do {
System.out.println("do" + j);
j++;
continue;
} while (j < 5);
for (int k = 1; k < 5; k++) {
System.out.println("for" + k);
continue;
}
}
@Test
public void testBreak() {
int i = 1;
while(i < 5) {
System.out.println("while" + i);
i++;
continue;
}
int j = 1;
do {
System.out.println("do" + j);
j++;
continue;
} while (j < 5);
for (int k = 1; k < 5; k++) {
System.out.println("for" + k);
break;
}
}
@Test
public void testVerschachtelteSchleifen() {
for (boolean b = false, c = false; b == false;) {
System.out.println("Outer oben");
for (; c == false;) {
System.out.println("inner oben");
if (!b) {
b = true;
continue;
}
if (b) break;
System.out.println("inner unten");
}
System.out.println("Outer unten");
b = true;
}
}
@Test
public void testLabel() {
außen:
for (int i = 1; i <= 10; i++) {
System.out.println("Outer oben " + i);
innen:
for (int j = 1; j <= 2; j++) {
continue außen;
// break außen;
// System.out.println("inner oben " + j);
// if (i > 2) {
// break innen;
// } else if (i > 4) {
// System.out.println("Break außen");
// break außen;
// }
// System.out.println("inner unten " + j);
}
System.out.println("Outer unten " + i);
}
System.out.println("Nach außen");
}
}

View File

@@ -0,0 +1,53 @@
package org.eidecker.oca8lernen.general;
import org.junit.jupiter.api.Test;
public class SwitchSyntax {
@Test
public void switchSyntax() {
Integer i = 1;
switch(getSwitchBEdingung()) {
case 1:
System.out.println("1");
default:
System.out.println("default");
}
}
// Todo SeEi
@Test
public void switchString() {
switch (getString()) {
case "Hallo":
System.out.println("Hallo");
default:
System.out.println("default");
case "Eins":
System.out.println("Eins");
}
}
@Test
public void switchEmptyAndDefaultOnly() {
switch (getString()) {
default:
System.out.println("default only");
}
switch (getString()) {
}
}
private Integer getSwitchBEdingung() {
return new Integer(1);
}
private String getString() {
return "Eins";
}
}