15. Are There Other Loops?

The for Loop

image

There is another type of C loop called the for loop. A for loop offers more control than while and do-while. With a for loop, you can specify exactly how many times you want to loop; whereas with while loops, you must continue looping as long as a condition is true.

There is room for all three kinds of loops in C programs. There are times when one loop fits one program’s requirements better than another. For example, if you wrote a program to handle customer orders as customers purchase items from the inventory, you would need to use a while ...

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.