14. Code Repeat—Using Loops to Save Time and Effort

In This Chapter

Saving time by looping through code

Using while

Using do...while

Now that you’ve learned the operators, you’re ready to play “loop the loop” with your programs. A loop is simply a section of code that repeats a few times. You don’t want a loop to repeat forever—that’s called an infinite loop. The loops you write (if you write them properly—and, of course, you will) should come to a conclusion when they finish doing the job you set them up to do.

Why would you want a program to loop? The answer becomes clear when you think about the advantage of using a computer for tasks that people wouldn’t want to do. Computers never get bored, so you should give them mundane and repetitive ...

Get C Programming Absolute Beginner’s Guide, Third Edition 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.