TOC | Prev | Next

for and while and semicolons

A common mistake is to have a stray semicolon. Instead of

i = 0;
while ( i < 100 )
    i++;

you write

i = 0;
while ( i < 100 );
    i++;

The while executes an empty statement because of the semicolon, and the i++ is never executed.

TOC | Prev | Next