File tree 1 file changed +54
-0
lines changed
1 file changed +54
-0
lines changed Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>While Loop in PHP</title>
7
+ </head>
8
+ <body>
9
+
10
+ <?php
11
+
12
+ # Loops are used to repeat a set of statements till a specific condition
13
+ # While loop execute till condition is true
14
+ # It stops after Condition is false
15
+
16
+ echo "<p>Using While Loop in PHP</p> " ;
17
+
18
+ # Creating Variable
19
+ # Initialization
20
+ $ x =1 ;
21
+
22
+ echo "Numbers from 1 to 10 using while loop are: " ;
23
+
24
+ # Printing Numbers from 1 to 10
25
+ while ($ x <=10 ){
26
+ echo $ x ." " ;
27
+ $ x ++;
28
+ }
29
+
30
+ # Creating Variable
31
+ # Initialization
32
+ $ y =10 ;
33
+
34
+ echo "<br><br>Numbers from 10 to 1 using while loop are: " ;
35
+
36
+ # Printing Numbers from 10 to 1
37
+ while ($ y >=1 ){
38
+ echo $ y ." " ;
39
+ $ y --;
40
+ }
41
+
42
+ echo "<br><br>Even Numbers from 10 to 1 using while loop are: " ;
43
+ $ y =10 ;
44
+
45
+ # Printing Even Numbers
46
+ while ($ y >=1 ){
47
+ if ($ y %2 ==0 ){
48
+ echo $ y ." " ;}
49
+ $ y --;
50
+ }
51
+
52
+ ?>
53
+ </body>
54
+ </html>
You can’t perform that action at this time.
0 commit comments