A for loop is a recurrence control arrangement that authorizes users to professionally write a loop that requires to be implemented a specific number of times.
A for loop is helpful when you recognize how many times a job is to be replicated.
The syntax of a for loop is:
for(initialization; Boolean_expression; update) { // Statements }
Here is the flow of control in a for loop:
Following is an example code of Java for a loop.
public class Test { public static void main(String args[]) { for(int x = 10; x < 20; x = x + 1) { System.out.print("value of x : " + x ); System.out.print("\n"); } } }
This will produce the following result:
value of x : 10 value of x : 11 value of x : 12 value of x : 13 value of x : 14 value of x : 15 value of x : 16 value of x : 17 value of x : 18 value of x : 19
Here at Intellinuts, we have created a complete Java tutorial for Beginners to get started in Java.