简体   繁体   English

for循环忽略boolean if语句

[英]for loop ignoring boolean if statement

The foreach loop is completely ignoring my if statement. foreach循环完全忽略了我的if语句。

        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());
        }

You've prematurely terminated your if statement with a semicolon: 你用分号过早地终止了你的if语句:

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

This makes the following block a freestanding block that will always execute. 这使得以下块成为永远执行的独立块。

I think this is something which you must have done unintentionally..... 我认为这是你必须无意中做的事情.....

if(infoBox.CheckPressed(event));

Please remove the semicolon in the above if Statement if声明,请删除上面的semicolon

您应该从if语句中删除分号

if(infoBox.CheckPressed(event));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM