The for
keyword indicates a loop in PHP. The for
loop executes a block of statements repeatedly until the specified condition returns false.
PHP Code: Create a script using a for loop to add all the integers between 0 and 30 and display the total
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Code4Example</title> </head> <body> <!-- create a script using a for loop to add all the integers between 0 and 30 and display the total. --> <?php $total =0; for($i=0; $i<=30;$i++){ $total+=$i; } echo "<h1>Total(0...30):$total</h1>"; ?> </body> </html> |
Output: