Do your increment at the beginning instead of at the end:
int i = -1;
while ( i <= 10 )
{
i++;
System.out.println(i);
if ( i == 8 )
{
continue;
}
// Presumably there would be some code here, or this doesn't really make much sense
}
Or, depending on the language, you could do it right in the while
statement (keeping in mind operator precedence in whether you choose i++
or ++i
)
int i = 0
while ( i++ <= 10 )
{
System.out.println(i);
if ( i == 8 )
{
continue;
}
// Presumably there would be some code here, or this doesn't really make much sense
}
I would question the use of a while
loop for this kind of structure though. If you want to use a counter in a loop, a for
loop is typically more appropriate.