Adscend

If Else Statement

Syntax:
if(condition)
{
     // execute this block if condition is true
}
else{
     // execute this block if condition is false
}
Conditional statements are used to perform different actions based on different conditions.
1.If else statements are also known as conditional statements. This simply means that they are able to take action or decision based on various conditions.
2. If else statements is used to check whether specified condition is true or false.
If the condition is true then the code of block inside if will be executed. If the condition is false then the code of block inside else will be executed.
3. If else statements allows the computer to make decisions based on the values of variables which can take the specified action based on the input that is given.
If the decision or condition is true then the code of block inside if will be executed. If the decision or condition is false then the code of block inside else will be executed.

Example: 1

<?php 
$num1
=20$num2=30
if (
$num1<$num2
  echo 
"This line will show on browser"?>
Output
This line will show on browser

Example: 2

<?php 
$num1
=20$num2=30
if (
$num2<$num1
  echo 
"This line will not show on browser"?>
Output
The browser will show nothing
Because, the condition is false and 30 is greater than 20.






No comments:

Post a Comment