A Python script must probe TCP ports 20 through 25 inclusive on every host in a list, and stop probing a host once any port answers. Which loop design meets all three requirements?
Show the answer
Correct answerA. Outer for over hosts; inner for p in range(20, 26), with break on the first open port
AWhy this is right: range(20, 26) includes port 25, and break exits only the inner port loop, so the next host is still probed.
BWhy not this: range(20, 25) stops at port 24 because the upper bound is excluded, so port 25 is never tested.
CWhy not this: Ports in the outer loop means break exits the host loop, skipping remaining hosts for that port instead of stopping per host.
DWhy not this: continue jumps to the next port instead of ending the loop, so probing of that host would not stop.
range() excludes its upper bound, so range(20, 26) covers ports 20-25. A break in the inner loop ends probing of that host only, and the outer loop moves on to the next host. Using continue merely skips to the next port, so probing would not stop.