khirulnizam

ulangan while for

Jul 13th, 2021
1,293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 0.73 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7.     <title>Ulangan</title>
  8. </head>
  9. <body>
  10.     <h1>Paparan nombor 1 hingga 100 (while)</h1>
  11.     <?php
  12.        //while loop
  13.        $x=1;//permulaan kiraan
  14.        while($x<=100){
  15.            echo "$x <br>";//papar nilai semasa $x
  16.             $x++;//tokok 1 kepada $x
  17.         }
  18.     ?>
  19.  
  20. <h1>Paparan nombor 100 hingga 1 (for)</h1>
  21.     <?php
  22.        //while loop
  23.        for($x=100; $x>=1; $x--){
  24.             echo "$x <br>";//papar nilai semasa $x
  25.             //$x--;//susut 1 kepada $x
  26.         }
  27.     ?>
  28.    
  29. </body>
  30. </html>
Advertisement
Add Comment
Please, Sign In to add comment