14. How Can I Do the Same Stuff Over and Over?

With while and do-while Loops

image

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 ...

Get Absolute Beginner’s Guide to C, 2nd 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.