Loops
Learn for, while and do-while loops for repeating tasks.
Java Code
Study the example and understand what each part does.
public class Main {
public static void main(String[] args) {
for (int i = 1; i <= 5; i++) {
System.out.println("Number: " + i);
}
}
}
Java code normally runs using the Java Development Kit on a computer, Android Studio or another Java development environment. This course page presents the code examples without pretending that the browser is running Java directly.
Expected Output / Result
Number: 1 Number: 2 Number: 3 Number: 4 Number: 5
Finished this lesson?
Mark it complete to update your course progress.