Tip of the week#6: 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 as follows:

if(condition)
{
   execute();
}

Now, if you want to go back to the code in future and add a second instruction

if(condition)
{
   execute();
   execute2();
}

you don’t have to worry about putting in the braces.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

FREE C Cheatsheet - Speed Up Your C Programming.

FREE C Cheatsheet - Speed Up Your C Programming.

Download a 7-page free cheat sheet for easy and quick access to C Concepts, Snippets, and Syntax.

Thank you! Check you inbox and access your cheat-sheet