Created
December 20, 2013 06:56
-
-
Save itskingori/8051313 to your computer and use it in GitHub Desktop.
Loops
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Exercise 07: Loops</title> | |
</head> | |
<body> | |
<?php | |
// Write 3 scripts that will print the letters of the alphabet to the browser using a; | |
// * For loop | |
// * While loop | |
// * Do...while loop | |
// Create array with the alphabet | |
$alphabet = array("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O", | |
"P","Q","R","S","T","U","V","W","X","Y","Z"); | |
$no_of_letters = count($alphabet); | |
// Output using For Loop | |
echo "For Loop"."<br/>"; | |
for ($i = 0; $i < $no_of_letters; $i++) { | |
echo $alphabet[$i]."<br/>"; | |
} | |
echo "<br/>"; | |
// Output using While loop | |
echo "While Loop"."<br/>"; | |
$i = 0; | |
while ($i < $no_of_letters) { | |
echo $alphabet[$i]."<br/>"; | |
$i++; | |
} | |
echo "<br/>"; | |
// Output using Do...While loop | |
echo "Do...While Loop"."<br/>"; | |
$i = 0; | |
do { | |
echo $alphabet[$i]."<br/>"; | |
$i++; | |
} while ($i < $no_of_letters); | |
?> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment