3REPEATING CODE: DEFINITE LOOPS

image

Computers shine when we have them repeat a process over and over. They tirelessly do exactly what we ask, whether it involves doing something 10, 100, or a billion times. In this chapter, we’ll learn about loops, statements that instruct the computer to repeat the execution of part of our program.

We’ll use loops to solve three problems: tracking the location of a ball under a cup, counting the number of occupied parking spaces, and determining how much data is available on a cell phone plan.

Problem #5: Three Cups

In this problem, we’ll track the location of a ball under a cup as the cups move. But the cups can ...

Get Learn to Code by Solving Problems now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.