Presentation is loading. Please wait.

Presentation is loading. Please wait.

Conditional statement & LOOPS

Similar presentations


Presentation on theme: "Conditional statement & LOOPS"— Presentation transcript:

1 Conditional statement & LOOPS
Chapter 5 Conditional statement & LOOPS

2 Conditional Statements
Very often when you write code, you want to perform different actions for different decisions:- If-statement If-else-statement If-elseif-else statement

3 Conditional Statements
#Example <?php $t = date(“H”); if ($t< “10”) { echo”Have a good morning”; } else if ($t < “20”) { echo”Have a good day”; } else { echo”Have a good night”; ?>

4 Conditional Statements
Selects one of many blocks of code to be executed <?php $favcolor = “red”; switch ($favcolor) { case “red”: echo”Your favourite color is red!”; break; case”green”: echo” Your favourite color is green!”; default: echo”Your favourite color is missing”; } ?>

5 Loops Often you want write code, you want the same block of code to run over and over again in a row. While Do..while For Foreach (Array)

6 Loops #Example 1 <?php $x = 1; while ($x <=5) {
echo “Number of x is : $x<br>”; $x++; } ?>

7 Loops #Example 2 <?php $x = 1; do {
echo “Your number is : $x<br>”; } while ($x <=5) ?>

8 Loops #Example 3 <?php for ($x = 0; $x <=10; $x++) {
echo”The number is : $x <br>”; } ?>

9 Loops #Example 4 <?php $num = array(“1”,”2”,”3”,”4”);
foreach($num as $val) { echo $num.”<br>”; } ?>

10 Exercise #Exercise 1 (write code using IF-ELSEIF-ELSE statement) Mark
Gred 80 – 100 A B Below 79 C

11 Exercise #Exercise 2 (write code using WHILE statement) Num Operation
5 4 + 10 3 2 1

12 Exercise #Exercise 3 (write code using FOR statement) Num Total, R
Status 1 If R more than 1300, display status equal to “High”, else status equal to “Low” 2 + 200 3


Download ppt "Conditional statement & LOOPS"

Similar presentations


Ads by Google