|
if(condition) statement;
Single/simple statement, and it's not a loop (for, while), might be put on the same line.
And never ever do;
if(condition) { statement; }
By the way, Alt 1 ought to be punishable ...
The number of "code fixes" I've seen in the form of;
if(condition)
statement;
being changed to
if(condition)
statement;
statement;
In one project I even found three statements ... Be safe, use BRACEs.
|
|
|
|
|
Alternative 3 is my favourite too.
|
|
|
|
|
{} are called braces, not brackets. Brackets are these things: ()
Anyway ... I prefer a language where they're not needed at all!
If condition Then ...do something
|
|
|
|
|
Or, perhaps, they are both brackets.
I like that you kvetch about the braces being called brackets, and then proceed to call parentheses brackets.
At any rate, both are subset members of a superset known as: brackets.
"There are three kinds of lies: lies, damned lies and statistics."
- Benjamin Disraeli
|
|
|
|
|
Being pedantic again, I think kvetch is a bit strong... it was only a little dig
But to go on (and on and bloody on!) about it ... the wonderful thing about the English language is its rich vocabulary. It's a shame to waste it.
|
|
|
|
|
So rich that I went to Yiddish! Oy vey!
"There are three kinds of lies: lies, damned lies and statistics."
- Benjamin Disraeli
|
|
|
|
|
A_Griffin wrote: Brackets are these things: () Actually those are parentheses. Brackets are []
Everyone is born right handed. Only the strongest overcome it.
Fight for left-handed rights and hand equality.
|
|
|
|
|
Common usage allows for either. But calling {} brackets is just wrong. Or American. (Same difference )
|
|
|
|
|
Certainly not "American".
() Parentheses
{} Braces
[] Brackets
|
|
|
|
|
Exactly. Not sure what he was talking about.
Everyone is born right handed. Only the strongest overcome it.
Fight for left-handed rights and hand equality.
|
|
|
|
|
A_Griffin wrote: Common usage allows for either. Where is it common to call () either parentheses or brackets?
Everyone is born right handed. Only the strongest overcome it.
Fight for left-handed rights and hand equality.
|
|
|
|
|
if(condition) {
} else {
}
Press F1 for help or google it.
Greetings from Germany
|
|
|
|
|
KarstenK wrote: I prefer the missing right option FTFY
GCS d-- s-/++ a- C++++ U+++ P- L+@ E-- W++ N+ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t+ 5? X R+++ tv-- b+(+++) DI+++ D++ G e++ h--- ++>+++ y+++* Weapons extension: ma- k++ F+2 X
|
|
|
|
|
You have shown wisdom.
Ravings en masse^ |
---|
"The difference between genius and stupidity is that genius has its limits." - Albert Einstein | "If you are searching for perfection in others, then you seek disappointment. If you are seek perfection in yourself, then you will find failure." - Balboos HaGadol Mar 2010 |
|
|
|
|
|
Yuck!
I have lived with several Zen masters - all of them were cats.
|
|
|
|
|
... indented properly
if (condition)
{
statement;
}
There are occasions when this is OK
if (condition) statement; But only when statement is short and obvious.
Anything longer than a dozen characters or so needs a new line, and braces. Modern IDE's handle the indentation for you, but they still get it wrong and it's easy to read
if (condition)
statement;
statement; wrongly, especially if you use the excreble 1TB indentation style
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
modified 12-Feb-18 4:06am.
|
|
|
|
|
... with typing less, unless it's a remnant of a previous refactor or I could be adding more code in that condition.
|
|
|
|
|
Even though I DO NOT want have Brackets around single line commands, but as soon as I write 'IF' my fingers AUTOMATICALY press curly brackets { } and then start writing code in it.
**This case is also applied to WHILE and FOR
Find More .Net development tips at : .NET Tips
The only reason people get lost in thought is because it's unfamiliar territory.
|
|
|
|
|
And that's a statement, not a command.
|
|
|
|
|
nope, braces are to hold your trousers up (what you Americans call suspenders)
|
|
|
|
|
Lord, you would think a site dedicated to programming would know the difference between brackets and braces by the people who write the surveys. Or at least QA them.
Latest Article - Code Review - What You Can Learn From a Single Line of Code
Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny
Artificial intelligence is the only remedy for natural stupidity. - CDP1802
|
|
|
|