Control Structures in Java
if (count > 2) {
System.out.println("Count is higher than 2");
} else {
System.out.println("Count is lower or equal than 2");
}
switch (count) {
case 0:
System.out.println("Count is equal to 0");
break;
case 1:
System.out.println("Count is equal to 1");
break;
default:
System.out.println("Count is either negative, or higher than 1");
break;
}
for (int i = 1; i <= 50; i++) {
methodToRepeat();
}
int whileCounter = 1;
while (whileCounter <= 50) {
methodToRepeat();
whileCounter++;
}
List<String> names = getNameList();
String name = "John Doe";
int index = 0;
for ( ; index < names.length; index++) {
if (names[index].equals(name)) {
break;
}
}
List<String> names = getNameList();
String name = "John Doe";
String list = "";
for (int i = 0; i < names.length; i++) {
if (names[i].equals(name)) {
continue;
}
list += names[i];
}