Student Tasks/Solution
Activity
Task 1: Guessing Game Mod - Guessing Game Mod
Task 2: Fireballs - Fireballs
Reflection/Homework
How are While loops different from For loops?
- While loops use a condition (logic expression, boolean value) to determine whether to continue running each iteration of the loop. Whereas For loops run a specific number of times.
Explain why picking up the fireSource allowed the player to keep making fireballs, without any other buttons being pressed.
- In the On Overlap event for the Player and the FireSource, we added 5 more lives to our Player, and as long as our Lives > 0 (condition in the While loop) we could continue shooting fireballs!
Challenge: If "IF statements" didnβt exist, could you use While loops to implement the same behavior in blocks? If so, how?
- Yes. Both While loops and Conditional statements evaluate a boolean expression. The difference is that While loops keep repeating and testing the same condition over and over again, so that's why usually inside the loop you need to change the value of one of the variables in the condition. You could use a While loop to do a branching function like a conditional statement, you would just need to exit the loop after running it once in the case the condition was true.