July 2018
Beginner
552 pages
13h 18m
English
The for loop is a loop that normally iterates a value and executes the same script with the iterated numeric value. The basic syntax of a for loop is as follows:
# basic syntax of a for-loopfor (<init>; <condition>; <repeat>){ <statement list>}
It starts with the for keyword, followed by an init statement, a condition, and a repeat statement. To give you a better overview, let's take a look at a simple example:
# Simple example - for-loopfor ($i = 0; $i -lt 5; $i++) {
$i }# 0, 1, 2, 3, 4
The init statement in our example is $i = 0, where we initialize an iterating variable, $i. The loop will run as often as the condition is fulfilled. In our example, with $i -lt 5, our loop will run 5 times, and the result will be 0, 1, 2, 3, ...
Read now
Unlock full access