forked from McJtyMods/ModTutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
For Loops!
Michael B edited this page Aug 15, 2017
·
1 revision
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:
-
int i=0; - This is setting a variable that will be used to count in a for loop.
-
i<20; - This is called the gate command. As long as this statement is true, it will continue to run through the loop.
-
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!