Post

Replies

Boosts

Views

Activity

Reply to Learn to Code 2 > Variables > Three Gems, Four Switches
The behaviour you are seeing is actually as expected, due to the way logical operators work in programming. When you use an OR (||) operator in your while condition, it means the loop will continue to execute as long as at least one of the conditions is true. So in your case, the loop will keep running if either gemsCollected < 3 OR switchesToggled < 4. Therefore, even if you have collected 3 gems, but have not toggled 4 switches, the loop will continue to run because the switchesToggled < 4 condition is still true.
Jul ’23