11. Which line is a loop variable update statement in the sample code? integer h = 0do Put "What is the password?" to output String userInput Get next input if userInput != pwd Put "Incorrect." to output h = h + 1while (userInput ! pwd) and (h <= 10) if userInput pwd Put "Access granted." to outputelse Put "Access denied." to output
Answer: C
h = h + 1
The loop variable update statement in the sample code is represented by the line "h = h + 1," which increments the variable h each time the loop iterates. This operation is essential for controlling the number of iterations in the loop.
A) (userInput != pwd) and (h
This option represents the loop's condition rather than the update statement. It checks whether the user input does not match the password and whether the count of attempts (h) is less than or equal to 10, but it does not modify any variables.
B) if userInput == pwd
This option is a conditional statement that checks if the user's input matches the password. It does not perform any updates to loop variables, thus is not relevant to the question regarding the loop variable update statement.
C) h = h + 1
This is the correct answer as it explicitly updates the loop variable h by incrementing it by 1. This update is crucial for controlling the loop's execution and ensuring it eventually terminates.
D) integer h = 0
This option initializes the loop variable h but does not update it during the loop execution. Therefore, it does not qualify as a loop variable update statement.
Conclusion
The correct answer, "h = h + 1," is definitively the loop variable update statement, as it modifies the variable responsible for tracking the number of iterations. All other options either represent conditions or initialization steps, failing to meet the criteria of a variable update within the loop.