Definitely
while(condition) {
stuff
}
and this
do {
stuff
} while( condition );
same goes for everything else, so for a try catch:
try {
} catch(Ex1 ex) {
} catch(Ex2 ex) {
}
and so on. My story is the opposite of most of the people here I think:
I started with Borland Turbo C++ and I used option 2, because I had just
switched from Pascal back then, so I just put the {} where I usually put
the open-close keyword (heck, it's been so long I can't remember what
the keywords are anymore. Was it Begin - End? I'm not sure).
Then later I read Bruce Eckel's book Using C++, in which he wrote about
why he used the no-newline-before-opening-brace style (i.e.: option 1).
Most of the reasons are about space (also he gives lots of seminar, so
even one line can matter a lot for his slides), but that was good enough
for me. Plus all the subsequent C++ books I read use that convention as
well.
So I started using 1, and never go back. Also then I moved to Java
before .NET, where option 1 is more common, thanks to the fact that you
have more than one choice for IDE in Java, plus they're not *that*
insistent on making you use option 2 like VS, in which every generated
piece of code by default uses 2.
A question to VS.NET users: How do you set it in VS.NET so that it'll
use option 1 when it *creates* a new file? I know I can format it, but I
don't want to have to format a file I just created everytime.
Morten Wennevik wrote:
A bit non topic but ...
When using code blocks which do you prefer
while( condition ) {
stuff
}
or
while( condition )
{
stuff
}
I prefer the latter version. I like to keep the curly braces on the same
indentation level.
But out of curiosity, what do YOU prefer?
Also in a do while which one would you prefer
do {
stuff
} while( condition );
do {
stuff
}
while( condition );
do
{
stuff
} while( condition );
do
{
stuff
}
while( condition );
I would prefer having the braces on the same indentation and alone.