6. Repeating actions with loops

Image

What you will learn

In this chapter, you’ll learn another step in how to control what a program does. Until now, we’ve written programs that run once and then stop when they’re complete. But you often need to make a program repeat a sequence of actions. For example, if a user enters an invalid value, you want the program to reject that value and repeat the sequence to ask for another value. To repeat a series of actions, programs use what’s known as a loop. In a video game, for example, the “game loop” continuously reads the positions of the game controllers, updates the variables that reflect the status of the ...

Get Begin to Code with C# now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.