Please enable JavaScript to view this site.

Process Designer

Looping allows you to automate and simplify repeating processes. This is especially useful for counting values or going through arrays. The mostly used loops in PHP are the for, while and for each loop. for-, die while- und die foreach-Schleife. Each loop has an initial condition, which influences the start of the loop and a termination condition that stops it from looping. The following examples all create the same output in different ways:

<?php

// The for loop

//initial condition; termination condition; statement

for ($i = 0; $i < 10; $i++) {

 echo $i;

 echo "<br/>";

}

 

// The while loop

$i = 0;

while ($i < 10) { // initial and termination condition in one

 echo $i;

 echo "<br/>";

 $i++;

}

 

// The foreach loop runs through all elements of an array

// Initial condition: array has more than 0 elements

// termination condition: Reaching the last value

$numberArray = array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);

foreach ($numberArray as $i) {

      echo $i;

      echo "<br/>";        

}

?>