Exercises
Now that we can iterate, it’s time to do some similar tasks to the chapters before but iterate for multiple values!
Be creative on how to implement these ones and add context where you need it. As always, there’s not one right answer:
- All of our dinosaurs are unique. Okay, we cloned their DNA, but still. Let’s say they have unique personalities. That’s why the IDs of all our dinosaurs are unique too: they are called
dino1
,dino2
,dino3
, and so on. Write afor
loop that prints out the IDs of the first 100 dinosaurs in the park. - Some of our dinosaurs have large appetites! Write a
do-while
loop that continues to feed a dinosaur until it is no longer hungry. - We all love the thrill of waiting for the park to open. Use a
while
loop to print out a countdown to the park’s opening time. - For planning purposes, it’s essential to know the total weight of all dinosaurs in a specific enclosure. Write a
for
loop that calculates...