Java: for loop test

Reading Time: < 1 minute

Last Update: 2/19/2025

This is a just a simple exemplar piece of code.

“foorlooptest.java”

// Your First Program

class Main {
    public static void main(String[] args) {
      for (int i = 0; i < 5; i++) {
         System.out.println("Iteration: " + i);
      }
    }
}
javac foorlooptest.java

This will produce a file named “Main.class”

You can then run the end result. The code compiled and placed into a class.

S:\forlooptest>java Main
Iteration: 0
Iteration: 1
Iteration: 2
Iteration: 3
Iteration: 4
This entry was posted in Java. Bookmark the permalink.