Iterations in essence is counting. You have to repeatedly do a task a certain number of times and the conditions within your loops determines how many times you do it. Whether you’re dealing with a for loop or a while loop you will need the following to count properly:
Check this video for visualization of the for loop:
https://www.youtube.com/watch?v=Hj0czMprXhc
for (int i=0; i<3; i++){
System.out.println(i);
}
// rest of the code
i is the variable initialized for the loopi<3 is the condition for the loop. The loop will run only if this condition is truei++ is the step: here we are incrementing i by 1 each time.for (int i=3; i>0; i--){
System.out.println(i);
}
// rest of the code
i is the variable initialized for the loopi>0 is the condition for the loop. The loop will run only if this condition is truei-- is the step: here we are decrementing i by 1 each time.