Self Answer Key: IF Statement Quiz 2

If button A is pressed, the servo will extend to 100%. However, we immediatel test button B and if it is not pressed, the else block is executed and the servo is retracted back to 0% extension. Physically, assuming the servo starts at 0% extension, you would observe the servo twitch and remain at 0% extension.

If we change the statement:

if B.isPressed()


else if B.isPressed()

then if A is pressed, button B will not be checked. If A is not pressed and then B is checked, you would get either 50% or 0% extension.

Click Next for another quiz on IF statements.