Monday, February 23, 2009

Always write if statements with braces

By putting braces around every block of code you write, you ensure that future edits won't introduce bizarre bugs.

If you have a one-line if statement:
if(<condition>)
execute();

you should still surround
execute();
with braces:
if(<condition>)
{
execute();
}

Now, if you go back and add a second instruction
if(<condition>)
{
execute();
execute2();
}

you don't have to worry about putting in the braces, and you know that you won't forget to put them in.
Author : Webmaster

0 nhận xét:

Post a Comment