Java: Control Flow
What you will learn
Conditionals, loops, and the traditional Java for-loop syntax.
int score = 85;
if (score >= 90) {
System.out.println("A");
} else if (score >= 80) {
System.out.println("B");
} else {
System.out.println("F");
}
Note else if is two words (not elif).
Traditional for loop
for (int i = 0; i < 5; i++) {
System.out.println(i);
}
Parts: initializer (runs once), condition (checked before each iteration), update (runs after each body). All three are optional -- for (;;) is an infinite loop.
Enhanced for (for-each)
int[] numbers = {1, 2, 3};
for (int n : numbers) {
System.out.println(n);
}
Quick check below!