2.4.4 if


Contents

Name

if

Description

The if statement controls conditional branching. The body of an if statement is executed if the value of the expression is nonzero.

Remark

Examples

EX1

void if_ex(int nn)
{
	if (nn > 0 && nn < 10) 
		out_int("nn=",nn);
}

EX2

void init_in_if_ex()
{
	if (int x = rand()) 
		out_int("x=",x);
	else 
		out_str("int x = rand()");	
	//x = 0; // x in then/else only

	if (int a = 1, b = -2; a + b) // OK (init-statement may have several)
		out_str("if (int a = 1, b = 2; a + b)");
}

Header to Include

See Also

Reference