|
Practice 3
Main | Static vs. Dynamic Websites | Using PHP | A Simple PHP Program | Variables and Operators | Practice 1 | Solution 1 | Loops | Practice 2 | Solution 2 | Functions | Practice 3 | Solution 3 | Conditionals | Practice 4 | Solution 4 For this exercise you will redesign the answer to Practice 2 so that the solution uses a function that takes an argument. Recall our solution to Practice 2.
<html>
I like
<? for ($i=0; $i < 5; $i++) {
echo "<br>";
} ?>
to space
<?
$i=0;
while ($i < 7) {
echo "<br>";
$i++;
} ?>
things
<? for ($i=0; $i < 6; $i++) {
echo "<br>";
} ?>
out
</html>
The above code is more elegant than a solution that might have copied and pasted the tag "<br>" several times. However, the above code is still not as neat as it could be, since in order to write it, you probably did some copying and pasting anyway. Write a version of the above that uses a function so that you only have to write your loop statement once. Use a for loop to implement this function. To complete this exercise you must:
jfulton [at] member.fsf.org
|