ទំព័រដែលថ្មីៗ

Sunday, December 8, 2013

For loop

                          i.   For Loop
ករណី For Loop យើងប្រើវា នៅពេលដែលយើងដឹងច្បាស់ថា កូដរបស់យើងនេះ វានិងត្រូវដំណើរការចំនួនប៉ុន្មានដង។
Syntax:
For (init counter; test counter; increament counter)
{
កូដដែលនិងត្រូវដំណើរការ
}



N
1
Code
<form method="post" target="_self">
            Summary:<input type="text" name="txts" value="<?php echo $_POST["txts"];?>" /><br />
pow by:<input type="text" name="txtp" value="<?php echo $_POST["txtp"];?>" />
<input type="submit" name="btnshow" value="Show" />
</form>
<?php
            $sum=empty($_POST["txts"])?"":$_POST["txts"];
            $pow=empty($_POST["txtp"])?"":$_POST["txtp"];
            $loop=1;
            $total="";
            for($loop=1;$loop<=$sum;$loop++){
                        if($loop==$sum)
                        echo "$loop<sup>$pow</sup>=";
                        else
                        echo "$loop<sup>$pow</sup>"."+";
                        $total=$total+pow($loop,$pow);
            }
            echo $total;
?>
Result


2
Code
<form method="get" target="_self">
            Number of Rows:<input type="text" name="rows" value=<?php echo empty($_GET["rows"])?"":$_GET["rows"];?>><br />
    Number of Cols:<input type="text" name="cols" value=<?php echo empty($_GET["cols"])?"":$_GET["cols"];?>>
<input type="submit" name="btnshow" value="show" />
</form>
<table border="1">
            <?php
                        $row=empty($_GET["rows"])?"":$_GET["rows"];
                        $col=empty($_GET["cols"])?"":$_GET["cols"];
                        $index="";
                        for($r=1;$r<=$row;$r++){
                                    echo "<tr>";
                                    for($c=1;$c<=$col;$c++){
                                                $index++;
                                                echo "<td>$index</td>";
                                    }
                        }?></table>
Result


0 សូមធ្វើការតំលៃផង:

Post a Comment

ស្វែងរក

 


MOM TENG
(Web Master , Designer , Journalist , and Video Editor )
Student of Social Communication and Journalism 2nd Generation and 2nd year in
Don Bosco Vocational Center Kep
Email : tengmom20@gmail.com , tengmom20@yahoo.com , tengmom20@hotmail.com , Tel :070286200
Skype : tengmom.donbsco.com , Twitter : momteng , Facebook : តេងវិជ្ជា ដុនបូស្កូ, Google+ : mom teng
My Another Website : cambodian1.wordpress.com , khmernowaday.blogspot.com, cambodianteng.blogspot.com/, My picasa , donboscoke.org
Youtube : My Videos
Address : Thmey Village , Prey Thom Commune , Kep City , Kep Province , Cambodia .
Thank!!!!!