You are writing a PHP script and you want to stop the execution of a loop once a certain condition is met. How would you do this using break?
- Use the break statement to terminate the current loop.
- Use the continue statement to skip the rest of the current iteration.
- Use the exit statement to stop the script execution.
- Use the return statement to exit the loop and return a value.
The correct option is: "Use the break statement to terminate the current loop." The break statement in PHP is used to stop the execution of the current loop and move to the line immediately following the loop. It allows you to prematurely exit the loop when a certain condition is met. Learn more: https://www.php.net/manual/en/control-structures.break.php
Loading...
Related Quiz
- The preg_match() function in PHP returns true if the pattern was found in the string and false otherwise.
- In a PHP do...while loop, if the condition is never true, the loop will still execute once.
- How do you handle errors when using output control functions in PHP?
- You have a PHP script and you need to execute a query in a MySQL database. How would you do this?
- Which of the following are valid ways to denote a comment in PHP?