|
We have seen that making a for-loop heading modify only one variable, such as k, allows you to separate the loop into two logical parts, which is highly desirable. But that only works if the for-loop heading is the only place where k is modified; if the loop body modifies k then the two parts are no longer logically separable.
In accordance with that, the standards require a variable that is modified in a for-loop heading not to be modified in the loop body. Here is an example of something that you should not do.
for(i = 1; i < n; i++) { ... i = n; ... }Some programmers do that kind of thing as a way of breaking out of a for-loop. But if you want to break out of a for-loop, use a break or return statement.
|