for i java code example

Example 1: java for loop

for(int i = 0; i < 10; i++)
{
  //do something
  
  //NOTE: the integer name does not need to be i, and the loop
  //doesn't need to start at 0. In addition, the 10 can be replaced
  //with any value. In this case, the loop will run 10 times.
  //Finally, the incrementation of i can be any value, in this case,
  //i increments by one. To increment by 2, for example, you would
  //use "i += 2", or "i = i+2"
}

Example 2: java for

for(int i=0; i<10; i++){	//creates a counting vatiable i set to 0
  							//as long as i is < 10 (as long the condition is true)
  							// i is increased by one every cycle
//do some stuff
}

Example 3: java for

String[] cars = {"Volvo", "BMW", "Ford", "Mazda"};
for (String i : cars) {
  System.out.println(i);
}

Example 4: for loop in java

// for loop in java
public class ForLoop
{
   public static void main(String[] args)
   {
      for(int x = 1; x <= 5; x++)
      {
         System.out.println(x);
      }
   }
}

Example 5: for loop java

for (int i = 0; i < 5; i++) {
  System.out.println(i);
}

Example 6: java loop

for (int i = 0; i < 10; i++) {
  System.out.println(i);
}

Tags:

Java Example