O'Reilly logo

Just Enough C/C++ Programming by Guy W. Lecky-Thompson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Recap

Looping is a valuable part of programming. Generally speaking, a for loop is used when:

  • You know the start value.

  • You know the end value.

  • You can get from start to end value by counting.

This is called a counted loop. You can count up or down or use any of the mathematical operators to manipulate the variable being used as a counter. You initialize the counter to the start value and then check it against an end value, which can be constant or derived.

A while loop is useful when you are testing for a given condition to arise where the number of iterations may vary, depending on the code executed within the loop itself. Thus, it is useful when you do not know how you will get from the start to the end value and need to do some complex processing ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required