Always use brackets in an if statement

Programming an if statement can cause problems if you don't use brackets. For example do not do the following:

if ($value == 5) //do something

The above code will work fine but problems may occur if you add more statements. For example:

if ($value == 5) //do something //do something else This second statement will not run

I have added a second statement to the code but the second statement will not run. This is because we have not used brackets which results in only the first statement being run. If we change our code to the following:

if ($value == 5) { //do something //do something else Brackets now cause all statements to run }

Our problem is now fixed. By placing the brackets on our if statement we run all the following code until the closing bracket. Therefore we should always ensure brackets are used as subtle bugs can creep into our code later on.