So I am making a memory type game and the problem is the program is not entering the if statement even though I know the values it is checking are equal because I printed both values out before the if statement. They both are 1. I know the if statement is satisfied/true because of this. I know it is not entering the loop because I put a print statement in the loop and do not see the console display that if statement. So I am going to post a small section of code-the code that I think is relevant since people get mad if I post the entire code. If you need the entire code, let me know and I will post it. Anyways, what I get printed to my console is:
1
1
Notice how the statement: "Round finished." is not there when it should be.
Here is the code:
else {
System.out.println(++numberOn);
System.out.println(currentPattern.size());
if (++numberOn==currentPattern.size()) {
System.out.println("Round finished.");
score++;
numberOn=0;
displayPattern();
}
else {
numberOn++;
}
}
The program is entering this big/first else statement 100% or else the first 2 statements wouldn't have ran. So I need to know why the if statement, line 4, isn't running when both sides are equal to each other. Thanks in advance.
++numberOn, which increments it. Then you compare it, which increments again. You're adding two to the value.