-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWhile-Loop.php
109 lines (85 loc) · 1.78 KB
/
While-Loop.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>While Loop in PHP</title>
</head>
<body>
<?php
# Loops are used to repeat a set of statements till a specific condition
# While loop execute till condition is true
# It stops after Condition is false
echo "<p>Using While Loop in PHP</p>";
# Creating Variable
# Initialization
$x=1;
echo "Numbers from 1 to 10 using while loop are: ";
# Printing Numbers from 1 to 10
while($x<=10){
echo $x." ";
$x++;
}
# Creating Variable
# Initialization
$y=10;
echo "<br><br>Numbers from 10 to 1 using while loop are: ";
# Printing Numbers from 10 to 1
while($y>=1){
echo $y." ";
$y--;
}
echo "<br><br>Even Numbers from 10 to 1 using while loop are: ";
$y=10;
# Printing Even Numbers
while($y>=1){
if($y%2==0){
echo $y." ";}
$y--;
}
echo "<p>Half Pattern using while loop is: </p>";
# Printing Half Pattern
$x=1;
while($x<=5){
$y=1;
while($y<=$x){
$y++;
echo "* ";
}
$x++;
echo "<br>";
}
echo "<p>Inverted Half Pattern using while loop is: </p>";
# Printing Inverse Pattern
$x=1;
while($x<=5){
$y=5;
while($y>=$x){
$y--;
echo "* ";
}
$x++;
echo "<br>";
}
echo "<p>Fibonacci Series using while loop is: </p>";
# Taking Number of terms as input
# Printing Fibonacci Series
$f0=0;
$f1=1;
echo $f0." ".$f1." ";
$i=0;
$n=7;
while($i<$n-2){
# Calculating next term
$fn=$f0+$f1;
# Printing next term
echo $fn." ";
# Storing value in variables
$f0=$f1;
$f1=$fn;
# Incrementing
$i++;
}
?>
</body>
</html>