OneBite.Dev - Coding blog in a bite size

do a for loop in java

Code snippet on how to do a for loop in java

  for (int i=0; i<10; i++) {
   System.out.println("The value of i is: " + i);
  }

This code prints out the numbers 0-9. The keyword “for” initiates the loop. The variable “i” is set to 0. This is the starting point of the loop. The statement “i < 10” indicates the end point of the loop as the value of “i” will reach 10 and not exceed it. The phrase “i++” means that “i” will be increased by 1 each time the loop runs. The statement within the loop, “System.out.println(“The value of i is: ” + i);” will be executed 10 times. Each iteration of the loop will print the value of the variable “i”.

java