How to write the if statement aright

157 阅读1分钟

I have been writing code for years ,one of the most difficult and annoyed questions is to write the if statement .

imaging now we are writing the codes to dispose the input of the users.

let's begin with the simplest situation .

if the judged condition is bool, such as :

we can simply change it to 


now, consider the another situation 


we can  change it to 


Now,let's talk about the last situation .


change it to 


Well, the difference between the last situation and others , is that the else of  others is opposite to the if , such as bool and !bool , but the condition of if of last situation is independent .