Since the while
loop takes a condition, what this would do is declare a new instance of line
every time the loop is run, because the condition is evaluated every time through the loop.
It works in a for
loop because the initializer (the first of the three semicolon-separated expressions) is run only once, at the start; the condition is the second expression. You would have the same problem trying to declare a variable in the condition expression of a for
loop.