Java : for loop

Posted in Conditional Loops, Java By Raj On December 9, 2017


The for loop is used if you know how many iterations you are going to do that means the number of iterations is fixed

Initialization: the initialization will be used to initialized the variable and it executes only once

condition: based on the condition the body of the loop will be executed if the expression evaluates true then the body of the loop will be executed otherwise the loop will be terminated

iteration: this increments or decrements the initialized variable

Output :

Example 2:

If you want iterate collections then you can use for each loop

Output :