FuzzDuck
FuzzDuck
For loop
FuzzDuck
For loop

For loop

The For loop, like the While loop, is repeating code until a certain condition is met. The construction of the For loop differs, however, as it does not only contain the condition to be met. It also the variable and the condition, which the variable has to meet before the loop ends.

In the example below, we have a for loop in which we declare the following:
1. Which int we want to match a specific condition
2. Which condition we want the int to match
3. How the int is going to be incremented by each loop run.

// --- Declaring starting point of the program run with "main" method --- //
public static void Main(string[] args){

 // --- For loop, with number 1. Incrementing by 1 and while number is less than 5 --- //
 for(int number = 1; number < 5; number++) {
  Console.WriteLine("Running for the " + number + ". time");
 }

 // --- Invoking 'ReadKey()' to make time to read the output --- //
 Console.ReadKey();

}
// --- Declaring starting point of the program run with "main" method --- //
public static void main(String[] args) {

 // --- For loop, with number 1. Incrementing by 1 and while number is less than 5 --- //
 for(int number = 1; number < 5; number++) {
  System.out.println("Running for the " + number + ". time");
 }

}
// --- For loop, with number 1. Incrementing by 1 and while number is less than 5 --- //
for($number = 1; $number < 5; $number++) {
 echo "Running for the " + $number + ". time";
}