6

I have a question, I have been reviewing some code and in one script, the authors use:

if(0){
    #do something
}

Any help in what if(0) means?

3
  • 2
    Could be just a placeholder for a real if statement.
    – zx8754
    Sep 20, 2015 at 21:27
  • 1
    That it’s bad code. ;-) Sep 20, 2015 at 22:01
  • What will be a better practice? I have seen this a lot of times. I thought this is usual...@Konrad Rudolph
    – whatsnext
    Jul 21, 2016 at 20:13

2 Answers 2

7

The author (most likely) put the block of code in an if statement so that they could easily remove it if necessary without having to comment it out (or remove it). Similar to if(true) or if(false), you just need to change one value and it would skip that code.

Upon reviewing the code, developers should remove these kinds of statements once they've finalized all their source code not to confuse others.

0
1

Looks like something that will never be executed, since 0 = FALSE. Most probably this is a manual switch to test some code in parenthesis.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.