During a data-center deployment you must write a Bash script that blocks further configuration steps until the HTTPS listener on the same host is accepting connections. The script will run nc -z localhost 443 every five seconds to test the port. Which basic loop construct lets the script automatically keep retrying as long as the command returns a non-zero exit status and then exit the loop immediately when the command succeeds, without extra negation or break statements?
An until loop that surrounds the test command.
A while loop that surrounds the test command.
A for loop that iterates over a fixed sequence of retry counts.
A case statement that evaluates the test command's exit status.
In Bash an until loop executes its body repeatedly while the test command returns a non-zero (false) exit status, and it stops as soon as that command succeeds (exit status 0). Because nc -z localhost 443 fails until the port is open, wrapping the command in an until loop makes the script wait and then continue automatically when the service is ready.
A while loop has the opposite logic (it repeats only while the test command succeeds), so it would loop after the port is already open and exit immediately when the port is closed. A for loop requires a predefined list or counter and would need extra logic to stop at the right time, while a case statement is used for single evaluations rather than continuous polling. Therefore, the until loop is the most appropriate construct.