The For Statement
14. Omitting the Test
Answer:
Yes. (Actually, a good answer would be "sounds dangerous", because it is.)
Omitting the Test
When the test part of a for
is omitted it is as if the value true were put in its place. So,
for ( initialize ; ; change )
loopBody ;
is the same as:
for ( initialize ; true ; change )
loopBody ;
This is done for compatibility with the language C. It should not be used in newly written programs.
Several syntactic oddities were included in Java so that it would look familiar to C programmers.
Question 14:
Could all three parts be omitted from a
for
?