PHP offers several control statements to control the flow of program execution based on different conditions. Some of the commonly used control statements in PHP are:
Example:
5) {
echo "x is greater than 5";
}
?>
Example:
phpCopy code
5) { echo "x is greater than 5"; } else { echo "x is less than or equal to 5"; } ?>
Example:
phpCopy code
Example:
";
$x++;
}
?>
Example:
phpCopy code
"; } ?>
Example:
";
}
?>
Example:
";
$x++;
} while ($x <= 5);
?>
Output:
The value of x is: 1
The value of x is: 2
The value of x is: 3
The value of x is: 4
The value of x is: 5
break and continue statement in php:
In PHP, the break and continue statements are control statements that are used to control the flow of execution in loops.
phpCopy code
"; } ?>
In this example, the loop will be terminated when $i is equal to 5, and the output will be:
pythonCopy code
The value of i is: 1 The value of i is: 2 The value of i is: 3 The value of i is: 4
Example:
phpCopy code
"; } ?>
In this example, the loop will skip over even numbers and continue with odd numbers, and the output will be:
The value of i is: 1
The value of i is: 3
The value of i is: 5
The value of i is: 7
The value of i is: 9
Note that both the break and continue statements can be used in any type of loop in PHP, including the for, while, and do-while loops.
Learners TV is a website that is designed to educate users and provide instructional material on particular subjects and topics.