Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
I get the error message "continue cannot be used outside of a loop" but it is inside a loop i think?
public void run() {
// TODO Auto-generated method stub
while (isItOK == true);{
//perform canvas drawing
if (!holder.getSurface().isValid()){
continue;
}
Canvas c = holder.lockCanvas();
c.drawARGB(255, 150, 150, 10);
holder.unlockCanvasAndPost(c);
Here is the cause of your error:
while (isItOK == true);{
remove ; before {
When you put a semicolon after a while loop statement, for example in your code:
while (isItOK == true);
It says to not do anything until that statement is no longer true. Therefore, your code will not commence until isItOK == false.
Simply put, by adding the semicolon you already closed your while loop, so "continue" is considered to be outside of it.
Remove the semicolon and it should work.
EDIT: My apologies, marcin_j, apparently I missed that you had already answered this question.
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
I hope my question was worded correctly.. here is a snippet of code, if I uncomment the line System.out.println(hs.add(ar)); console will print true, so why are reaching inside the following if statement?
public static void duplicateExists(String [] array)
{
Set<String> hs = new HashSet<String>();
for (String ar : array)
{
// System.out.println(hs.add(ar));
if((hs.add(ar)) == false);
{
System.out.println("reaches here every time but shouldn't ");
}
}
}
public static void main(String[] args) {
duplicateExists(new String[] {"1","2","5","3","6","8"});
}
This line:
if((hs.add(ar)) == false);
Does nothing, because of the ending semicolon. The element is actually added to the set, despite the condition of the if is never satisfied.
Then, you have the following block of code:
{
System.out.println("reaches here every time but shouldn't ");
}
It's awkward, but in Java, you can have arbitrary blocks of code surrounded by braces. This one is always executed, because (due to the semicolon) is totally independent of the previous if.
Try removing the semicolon:
if ((hs.add(ar)) == false) {
System.out.println("reaches here every time but shouldn't");
}
Formatting the code might be seen as something not very important, but here is a case that clearly shows that when code is not nicely formatted, unintuitive, unexpected, hard-to-debug issues might happen.
Besides, you could simplify your code:
if (!hs.add(ar)) {
System.out.println("reaches here every time but shouldn't");
}
Now it doesn't reach the println.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
Currently new to java, and right now I'm doing an assignment involving if else statements. Can someone please why javac is reading my else as dangling? My syntax should be right unless I am missing something here.
You have to remove your Semicolon after the if-statement. Otherwise the braces after the if are not executed.
I hope this will fix your Problem.
if(Statement);
{
//The Content would not be executed in realtion to the if-statemen
}
Otherwise:
if(Statement)
{
//The Content would be executed in realtion to the if-statemen
}
remove the semicolon(;) after the if statement
You have a semicolon after your if. Remove it.
You have to remove the ; at the end of the line starting with if.
change :
if(...);
{
////
}
to
if(...)
{
////
}
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
Can you please help me make the following code work?
for(int a=0, b=0; a<101; b<102; a++; b++;) {
stuff
}
You got the initialization (first) part of the loop right.
The termination or condition (second) part of the loop should be evaluated to a boolean, so assuming you require an AND relation between the conditions on a and b, it becomes a<101 && b<102. You might want || (OR) instead, depending on your logic.
The increment (third) part of the loop should contain comma separated expressions (same as the initialization part which you already got right).
I also removed an extra ';' from the end.
for(int a=0, b=0; a<101 && b<102; a++, b++) { stuff }
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
If I have an if statement that includes a string like this:
double GUInumber1 = ((GUInumber1 >= 0 || <= 0)? Double.parseDouble(GUIfirstNumber) : 0);
('GUIfirstNumber' is the string)
Why does it come up as a error? Do I need brackets somewhere, do I need to use 'If/else' instead?
Supposedly my compiler says it does not recognize or (||), is this supposed to be something else or does this work in a completely different way.
Any help on this situation would be appreciated, also, if you need to know or are just wondering why I want to make a if statement for a string its because whenever I try to put in a letter instead of a number Java crashes, I'm hoping I could get this to alternatively solve the situation instead.
EDIT:
Solved, had to remove 'or' statements and alternatively make more else statements instead.
This expression (GUInumber1 >= 0 || <= 0) is not correct.
You will need something on both sides of the <= operator.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
I'm trying to count the number of items in a scanner object which are divisible by 2.
My code looks like this:
while (s.hasNext()) {
num = s.nextInt();
if ((num % 2) == 0); {
count++;
}
}
For every integer in the object though, count is increasing by 1, regardless if it is divisible by 2, or not. Can someone tell me what I'm doing wrong?
You have a semicolon (;) after your if clause. That means empty code is executed if the condition is true and the code in the code block is always executed.
The ; after the if should be omitted