CODE
<?php
// Simple for now
$number = 12; // Any number for instance
for($x=0; $number>$x; $x++)
{
echo "Number: $x<br>";
}
?>
// Simple for now
$number = 12; // Any number for instance
for($x=0; $number>$x; $x++)
{
echo "Number: $x<br>";
}
?>
The Low down:
for(
Start a 'for' function, which means, while the inside of the brackets () are happening you do what is inside the brackets {}
$x=0;
So $x is equal to 0 now, so we know where we start!
$number>$x;
While $number is bigger than $x (12 is bigger than 0) we do what follows
$x++)
We now add 1 onto the $x, so 0 is now 1, and so forth
{
echo "Number: $x<br>";
}
So while $number is bigger than $x (12 bigger than 0++) we echo the number! And once 12 is no longer bigger than 0, and $x = $number it stops the code and stops adding onto $x!
Alittle more complex:
CODE
<?php
// Symbolising, begin the code
// Let's start basic:
$number = 12; // Any number for instance
for($x=0; $number>$x; $x++)
{
echo "Number: $x<br>";
}
else
{
echo "The allotted number was achieved!<br>Restart?<br><a href="$PHP_SELF">Yes</a>"; }
// End the code now:
?>
// Symbolising, begin the code
// Let's start basic:
$number = 12; // Any number for instance
for($x=0; $number>$x; $x++)
{
echo "Number: $x<br>";
}
else
{
echo "The allotted number was achieved!<br>Restart?<br><a href="$PHP_SELF">Yes</a>"; }
// End the code now:
?>
else
{
Now that the $x = $number we use this command instead
echo "The allotted number was achieved!<br>Restart?<br><a href="$PHP_SELF">Yes</a>";
We echo that the number was achieved and if they wish to start again
}
That's it! We ended the new loop
I understand the tutorial is lacking in greatness, but I rushed it and well, I am assuming that most of you can pick this code up and adapt it to suit your needs.