Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

for loop ignoring boolean if statement

Tags:

java

android

The foreach loop is completely ignoring my if statement.

        for(InfoBox infoBox : mAbilities)
        {
            if(infoBox.CheckPressed(event));
            {
                //This is being outputted each time, even if the if statement returns false.
                System.out.println(infoBox.getName());
            }

            System.out.println(infoBox.CheckPressed(event));
            System.out.println(infoBox.getName());
        }
like image 403
Abakiz Myth Avatar asked Feb 16 '26 13:02

Abakiz Myth


1 Answers

You've prematurely terminated your if statement with a semicolon:

if(infoBox.CheckPressed(event));  // <-- remove the semicolon

This makes the following block a freestanding block that will always execute.

like image 107
pb2q Avatar answered Feb 19 '26 02:02

pb2q



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!