206k views
2 votes
Consider the following code segment that appears in the middle of a program. display [what is the password?] EnterPassword<– input Repeat Until (missing statement) display[invalid, try again] userPassword <– Input Which of the following can replace the missing statement in the REPEAT UNTIL block so that the user will be required to enter the correct password of 'swordfish' before they can continue on with the rest of the program?

1) userPassword ≠ 'swordfish'
2) userPassword = 'swordfish'
3) userPassword == 'swordfish'
4) userPassword != 'swordfish'

User Jacajack
by
6.9k points

1 Answer

3 votes

Final answer:

To ensure the program only continues when the correct password 'swordfish' is entered, which states 'userPassword ≠ 'swordfish'', should replace the missing statement in the REPEAT UNTIL block. (option 1)

Step-by-step explanation:

To complete the REPEAT UNTIL loop correctly, we need a condition that keeps looping until the correct password is entered. Option 1, userPassword ≠ 'swordfish', would be correct because it translates to 'repeat until the userPassword is not equal to swordfish' which implies that the loop will continue until the variable userPassword equals 'swordfish'. When the correct password is entered, the condition becomes false, and the loop stops repeating.

Using 'userPassword' ≠ 'swordfish' ensures that the loop will repeat until the user enters the correct password. Once the correct password is provided, the condition becomes false, and the loop terminates, allowing the program to continue.

This condition aligns with the logic of verifying that the user's input is not equal to 'swordfish,' effectively enforcing the requirement for the correct password to progress in the program.

Therefore, the correct replacement for the missing statement in the REPEAT UNTIL block is option 1.

User BenRollag
by
6.8k points