Semicolon at end of 'if' statement

前端 未结 18 1629
没有蜡笔的小新
没有蜡笔的小新 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:42

    if(a==b)
        println("a equals b");
    

    You can use an IF statement without {} if there is only a single line to be executed, so by using if(a==b); you are saying if they equal, execute and empty statement... So it will do nothing, and then return to your normal loop, outside of the IF block.

提交回复
热议问题