Improper For Loop Declarations


When you create a for loop, the second element of the declaration tells the loop under what conditions to execute. It does not tell the loop where to stop. For example if you say the following:

for (int j = 0; j < 10; j++)

You have told the loop to execute as long as j is less than 10. This is exactly correct. A common beginner mistake is to write this as:

For (int j = 0; j = 10;j++)

This will never work. You have instructed the loop to execute as long as j is equal to 10, yet you initialized j to 0. That means the loop will never execute!




C++ Programming Fundamentals
C++ Programming Fundamentals (Cyberrookies)
ISBN: 1584502371
EAN: 2147483647
Year: 2005
Pages: 197
Authors: Chuck Easttom

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net