How many times will a for loop be executed?

1 answer

Answer

1274001

2026-08-08 19:55

+ Follow

As many times as necessary. There is no practical limit because all loops rely on a control expression that can only evaluate true or false. So long as the control expression evaluates true, the loop will just keep iterating. The canonical example is the infinite loop:

while (true) {

// ...

}

The control expression never evaluates false, so the only way to break out of this loop is from within the body of the loop itself. Although we typically use infinite loops when the control expressions are far too complex to be expressed as a simple expression in the while statement, we can easily avoid this by placing those control expressions in a function. For example, if the control expressions depend on three variables, a, b, c, we can pass those variables to a predicate function that returns true or false:

while (evaluate (a, b, c));

Here, the overall complexity of the control expression is hidden within the evaluate function, greatly simplifying the calling code.

ReportLike(0ShareFavorite

Copyright © 2026 eLLeNow.com All Rights Reserved.