Thursday, February 3, 2011

Exercise For Loop

Assalamu'alaikum and selamat sejahtera

After we learn the concept and practical of For loops.So...why dont us do some activity,this activity is called MathForLoops,the objective or cause is that we try to apply the math operation in For loops.Well as previous post,we already apply it on update , $counter and $number ,if u remember.Ok,for this post,we will do math table like times,minus,add and divide.The hint is refer the image below...i use add table,and u will do the other table.okey?hehe

Input:

Result:

Code:

<html>
<head>
<title>An Addition Table Programme</title>

<?PHP
    $add = 2;

if (isset($_POST['SubmitOne'])) {

    $initial = $_POST['txtInitial'];
    $final = $_POST['txtFinal'];
    $add = $_POST['txtAdd'];


    for($initial; $initial <= $final; $initial++) {
        $answer = $initial + $add;
        print $initial . " added by " . $add . " = " . $answer . "<BR>";
    }

}

?>

</head>

<body>


<FORM NAME = formOne Method = "POST" Action = "forloops.php">

Start Number: <INPUT TYPE = Text NAME  = txtInitial SIZE = 5 value ="1">
End Number: <INPUT TYPE = Text NAME = txtFinal SIZE = 5 value ="10">
Add By: <INPUT TYPE = Text NAME = txtAdd SIZE = 5 value = <?PHP print $add; ?> >
<P>
<INPUT TYPE = Submit Name = SubmitOne VALUE = "Do Add Table">
<P>

</FORM>
</body>

<html>

File name: forloops.php

N/NOTE:Try ur self!

No comments:

Post a Comment