Does it need a ";" at the very after of "if" and "for"

M

marsarden

write code like:

int main(void)
{
int a=10;
if(a<20)
{}
}

Compiler ok on dev-cpp . don't we have to add a ";" after if
statement?
 
R

Richard Heathfield

marsarden said:
write code like:

int main(void)
{
int a=10;
if(a<20)
{}
}

Compiler ok on dev-cpp . don't we have to add a ";" after if
statement?

The syntax for 'if' is:

if(expression) statement

There is no semicolon after the ) but before the statement.

The statement is either a normal statement (which can be empty), ending in a
semicolon:-

if(expr)
foo();

if(expr)
;

or a list of zero or more statements enclosed in braces:

if(expr)
{
foo();
bar();
}

if(expr)
{
}
 
M

marsarden

Richard said:
marsarden said:


The syntax for 'if' is:

if(expression) statement

There is no semicolon after the ) but before the statement.

The statement is either a normal statement (which can be empty), ending in a
semicolon:-

if(expr)
foo();

if(expr)
;

or a list of zero or more statements enclosed in braces:

if(expr)
{
foo();
bar();
}

if(expr)
{
}


--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)

Thx alot .
 

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,796
Messages
2,569,645
Members
45,371
Latest member
TroyHursey

Latest Threads

Top