Semicolon at end of 'if' statement

前端 未结 18 1913
没有蜡笔的小新
没有蜡笔的小新 2020-11-22 01:01

Today, after half an hour of searching for a bug, I discovered that it is possible to put a semicolon after an if statement instead of code, like this:

if(a          


        
18条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-22 01:21

    Just a FYI about the usability and what difference it makes or can make if there is a statement like that

    Consider a piece of code like the following.

    int a = 10;
    if ((a = 50) == 50);
    
    System.out.println("Value of a = " + a);
    

    Clearly in this case, the if statement does change the output. So a statement like that can make a difference.

    This is a situation where this could be useful or better to say have an impact on program.

提交回复
热议问题