File tree 2 files changed +151
-0
lines changed
2 files changed +151
-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>Do 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
+ # Do While loop execute till condition is true
14
+ # It stops after Condition is false but atleast one time statement is still executed
15
+
16
+ echo "<p>Using Do While Loop in PHP</p> " ;
17
+
18
+ # Creating Variable
19
+ # Initialization
20
+ $ x =1 ;
21
+
22
+ echo "Numbers from 1 to 10 using Do While loop are: " ;
23
+
24
+ # Printing Numbers from 1 to 10
25
+ do {
26
+ echo $ x ." " ;
27
+ $ x ++;
28
+ }while ($ x <=10 );
29
+
30
+ # Creating Variable
31
+ # Initialization
32
+ $ y =10 ;
33
+
34
+ echo "<br><br>Numbers from 10 to 1 using Do While loop are: " ;
35
+
36
+ # Printing Numbers from 10 to 1
37
+ do {
38
+ echo $ y ." " ;
39
+ $ y --;
40
+ }while ($ y >=1 );
41
+
42
+ echo "<br><br>Even Numbers from 10 to 1 using Do While loop are: " ;
43
+ $ y =10 ;
44
+
45
+ # Printing Even Numbers
46
+ do {
47
+ if ($ y %2 ==0 ){
48
+ echo $ y ." " ;}
49
+ $ y --;
50
+ }while ($ y >=1 );
51
+
52
+ echo "<br><br>Half Pattern using Do While loop is: <br> " ;
53
+
54
+
55
+ # Printing Half Pattern
56
+ $ x =1 ;
57
+ do {
58
+ $ y =1 ;
59
+ do {
60
+ $ y ++;
61
+ echo "* " ;
62
+ }while ($ y <=$ x );
63
+ $ x ++;
64
+ echo "<br> " ;
65
+ }while ($ x <=5 );
66
+
67
+ echo "<br><br>Inverted Half Pattern using Do While loop is: <br> " ;
68
+
69
+ # Printing Inverse Pattern
70
+ $ x =1 ;
71
+ do {
72
+ $ y =5 ;
73
+ do {
74
+ $ y --;
75
+ echo "* " ;
76
+ }while ($ y >=$ x );
77
+ $ x ++;
78
+ echo "<br> " ;
79
+ }while ($ x <=5 );
80
+
81
+ ?>
82
+ </body>
83
+ </html>
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>For Loop in PHP</title>
7
+ </head>
8
+ <body>
9
+
10
+ <?php
11
+
12
+
13
+ # Loops are used to repeat a set of statements till a specific condition
14
+ # For loop execute till condition is true
15
+ # It stops after Condition is false
16
+
17
+ echo "<p>Using For Loop in PHP</p> " ;
18
+
19
+ # Initialization and increment/decrement can be done directly in the loop
20
+
21
+ echo "Numbers from 1 to 10 using For loop are: " ;
22
+
23
+ # Printing Numbers from 1 to 10
24
+ for ($ x =1 ;$ x <=10 ;$ x ++){
25
+ echo $ x ." " ;
26
+ }
27
+
28
+ echo "<br><br>Numbers from 10 to 1 using For loop are: " ;
29
+
30
+ # Printing Numbers from 10 to 1
31
+ for ($ y =10 ;$ y >=1 ;$ y --){
32
+ echo $ y ." " ;
33
+ }
34
+
35
+ echo "<br><br>Even Numbers from 10 to 1 using For loop are: " ;
36
+ $ y =10 ;
37
+
38
+ # Printing Even Numbers
39
+ for ($ y =10 ;$ y >=1 ;$ y --){
40
+ if ($ y %2 ==0 ){
41
+ echo $ y ." " ;}
42
+ }
43
+
44
+ echo "<br><br>Half Pattern using For loop is: <br> " ;
45
+
46
+
47
+ # Printing Half Pattern
48
+ for ($ x =1 ; $ x <=5 ; $ x ++){
49
+ for ($ y =1 ; $ y <=$ x ; $ y ++){
50
+ echo "* " ;
51
+ }
52
+ echo "<br> " ;
53
+ }
54
+
55
+ echo "<br><br>Inverted Half Pattern using For loop is: <br> " ;
56
+
57
+ # Printing Inverse Pattern
58
+ for ($ x =1 ; $ x <=5 ; $ x ++){
59
+ for ($ y =5 ; $ y >=$ x ; $ y --){
60
+ echo "* " ;
61
+ }
62
+ echo "<br> " ;
63
+ }
64
+
65
+ ?>
66
+
67
+ </body>
68
+ </html>
You can’t perform that action at this time.
0 commit comments