Java provides several types of loops, with for being the most versatile. Here are some basic types of for loops.
To run the program, compile it and then use java:
Java’s for loop is quite flexible and can be used in various ways. We’ll see some other loop forms later when we look at enhanced for loops (for-each), which are useful for iterating over collections and arrays.