Stage 1 · Lesson 4 of 9
Conditionals and loops
(if, else if and else) choose between paths, and switch picks between many values. Its arrow form, case "a" -> ..., avoids the bugs of the old colon form, where one case runs on into the next. The classic , for (int i = 0; i < n; i++), gives you a position number.
The , for (String s : names), walks the values directly. A while loop repeats until a condition changes. break leaves a loop and continue skips a pass.
Conditions must be true or false: Java will not treat 0 or null as false, which removes a whole class of bugs other languages have. Trace small loops on paper, especially where they start and stop, because errors cause most ArrayIndexOutOfBoundsException crashes.
A question to check yourself, an AI practice session and 2 cheat sheet entries come when you add the roadmap to your account. Add it
Resources for this stage
Start with· follow one of these
- CourseFreeJava Programming MOOC
University of Helsinki · Beginner
Free Helsinki course with hundreds of auto-tested exercises; parts 1 to 8 cover this stage
- GuideFreeDev.java: Learn Java
Oracle · Beginner
Official tutorials from the Java team: read the language basics path next to the MOOC