Click here to Skip to main content
11,790,021 members (49,614 online)
Click here to Skip to main content

Tagged as

"if" with no code block parenthesis

, 12 Feb 2011 CPOL 11.8K 1
Rate this:
Please Sign up or sign in to vote.
Avoid using "if" with no code block parenthesis
Though it is supported, You should not use "if" without parenthesis for code block.

You should use:
// Your code 

and you should not use:

// Your code

One of my colleagues encountered the problem due to the unparenthesized "if".

The story goes like this:

His code was like this:
   System.out.println("This is log message to be printed on Console");
for( int i = 0; i < 10; i ++ )
    //Some important Code 
For final release, he globally replaced the System.out.println with //System.out.println so that all SOP statements would be commented.
But due the use of unparenthesized "if", the for loop went inside the if which was not desirable.

and the product started crashing.....

So the situation was ....Product was running properly if we keep all SOP.

After scanning the code throughly, we found out the culprit .....if with no code block parenthesis OMG | :OMG:


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer Symantec Corporation
India India
No Biography provided

You may also be interested in...

Comments and Discussions

sudheer muhammed10-Feb-11 0:40
membersudheer muhammed10-Feb-11 0:40 
Abdur Rehman Raza Khan - dontumindit13-Feb-11 11:44
memberAbdur Rehman Raza Khan - dontumindit13-Feb-11 11:44 
No there is no rule, but the above situation is common once we try to do some change in hurry, so its good to use if with brackets from start to avoid such time consuming effort at later stages

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.1509028.1 | Last Updated 13 Feb 2011
Article Copyright 2011 by PrafullaVedante
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid