bradc14 bradc14 - 2 months ago 10
Java Question

Error: not a statement when declaring a boolean in Java

The following code:

boolean continue = false;

Returns the following error:

error: not a statement
boolean continue = false;

Why is this happening? I am pretty familiar with booleans.


Try this instead:

boolean cont = false;

Or use another name. The point is that in Java, continue is a keyword and it can't be used as a variable name - it's right here in the language specification. For future reference this is what continue is used for:

The continue statement skips the current iteration of a for, while, or do-while loop. The unlabeled form skips to the end of the innermost loop's body and evaluates the boolean expression that controls the loop.