Skip to content
Michael B edited this page Aug 15, 2017 · 1 revision

For Loops: What are they?

A for loop is very similar to a while loop, in that it has a set of instructions to end the loop. The for loop has three parts to it: Let's look at an example for loop:

 for(int i=0; i<20; i++;){
      System.out.println("Count: " + i); 
}

Here is a break down of this:

  1. int i=0; - This is setting a variable that will be used to count in a for loop.

  2. i<20; - This is called the gate command. As long as this statement is true, it will continue to run through the loop.

  3. i++; This command runs every time the loop is completed.

The For Loops is an incredible and powerful tool that can be used in place of a for loop when your loop is used based on the number of times the loop needs to run!

Clone this wiki locally