Thursday, February 15, 2018

Jumanji and the While Loop

Cultural references (term used loosely) can make projects and exercises more interesting for students. Now that there is an updated version of the movie Jumanji out I decided to use that reference again for working with while loops.

If you remember the movie, you will probably remember that people playing the game can be forced to wait in the jungle until another player rolls a 5 or an 8. There are several ways you can use this in an exercise. You can “roll” dice once and use an if statement to report if the person can leave the jungle or not. OK but boring. Or you can simulate rolls to see how many “moves” it takes to get someone out of the jungle. That’s what we did.

There are several things I like about this exercise. We start by asking if the loop should check at the top or the bottom. Of course you can write it either way but the discussion is the valuable part.

Next we take on how the Boolean expression is formed. Finally we talk about the code inside the loop. One die with a range of 1 to 12 or two die with a range of 1 to 6? Which one better simulates real game play and why? Finally we talk about how to do the counting inside the loop.

image

All in all I find it a helpful exercise. As a demo it is simple enough to show the basics but involved enough to have some good conversations about how and why we do things different ways. And it is relatable to things outside of school.

No comments:

Post a Comment