I'm going through K.N. King's introductory C Programming: A Modern Approach (2e) and every time I see the code in the book, I can't help but wonder what's the better way to write your code in the following situation. Should I use the curly brackets or not, and how much does it matter? Here are the three versions of the same idea (I guess the last version is the worst):
Version 1, with curly brackets:
while(1) {
if(1) {
i++;
}
}
Version 2, without curly brackets:
while(1)
if(1)
i++;
Version 3, condensed version of the above code:
while(1)
if(1) i++;
Personally, I've been using the first version for 2 years now (I've previous PHP experience), but looking at it again, all those curly brackets seem like overkill. On the other hand, it's arguably easier to add a second expression to the loop or the conditional. But the second version looks cleaner, somehow it reminds me of Python, and I thought of using it, but I wanted to know if it were considered good practice, before picking up any bad habits. Thanks!