What is the correct syntax for checking a condition in a PHP script to exit a loop based on user input?

To exit a loop based on user input in a PHP script, you can use a conditional statement within the loop to check if the user input meets a certain condition that indicates the loop should stop. This can be achieved by using an if statement to check the user input and using the break keyword to exit the loop if the condition is met.

$continue = true;

while($continue) {
    // code inside the loop

    // check user input
    $userInput = readline("Do you want to continue? (y/n): ");
    if ($userInput !== 'y') {
        $continue = false;
    }
}