C Nested if Statements
In the C language,NestedThe if-else statement is legal, which means you can in aiforelse ifusing another within a statementiforelse ifstatement.
Syntax
In C languageNested ifSyntax of the statement:
if( boolean_expression 1)
{
/* 当布尔表达式 1 为真时执行 */
if(boolean_expression 2)
{
/* 当布尔表达式 2 为真时执行 */
}
}
You can nestelse if...else, in a manner similar to nestingifsimilar to statements.
Example
Example
#include <stdio.h>
int main ()
{
/*Local variable definition*/
int a = 100;
int b = 200;
/*Check boolean condition*/
if( a == 100 )
{
/*If the condition is true, check the following condition*/
if( b == 200 )
{
/*If the condition is true, print the following statement*/
printf("The value of a is 100, and the value of b is 200\n" );
}
}
printf("The exact value of a is %d\n", a );
printf("The exact value of b is %d\n", b );
return 0;
}
When the above code is compiled and executed, it produces the following results:
a 的值是 100,且 b 的值是 200 a 的准确值是 100 b 的准确值是 200other extensions