what will happen if we print the following...

J

James Kanze

for( ; ; );
printf("Hi");

It does nothing, and tekes forever to do it.

In many shops, putting a semicolon on the same line, after the
for, will also get you fired. If you want to write an empty
loop, at least put the empty statement on the following line,
either:

for ( /* ... */ )
;

or

for ( /* ... */ ) {
}

(or whatever bracing style the local conventions calls for).
 
R

red floyd

James said:
It does nothing, and tekes forever to do it.

In many shops, putting a semicolon on the same line, after the
for, will also get you fired. If you want to write an empty
loop, at least put the empty statement on the following line,
either:

for ( /* ... */ )
;
Even better is:

for ( /* ... */ )
/* do nothing */ ;
 
J

James Kanze

Even better is:
for ( /* ... */ )
/* do nothing */ ;

If the company accepts loops without braces. I use:

for ( /* ... */ ) {
}

But all my control statements use braces, always. And while an
empty set of braces is fairly visible, you're right that a
single ';' doesn't show up very well, and something more doesn't
hurt.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top