Nesting IF in C

Nested if statement is same as if..else statement the nested if is execute inner if condition in the single if statement for execute if into if condition and execute else part in the nesting if condition.

Syntax


if(true condition)	
{
	if(true condition)
	{
		statement;
	}
	else
	{
		statement;
	}
}	
else
{
	statement;
}					
							

Example

in this example check username and password using nesting if condition.


#include<stdio.h>
#include<conio.h>

void main()
{
	char uname;
	char pass;
	clrscr();
	
	printf("Enter Your Username:");
	scanf("%c",&uname);
	
	printf("Enter Your Password:");
	scanf("%c",&pass);
	
	if(uname == 'bharat')
	{
		if(pass == 'makwana')
		{
			printf("Welcome Mr. Bharat Makwana");
		}
		else
		{
			printf("Sorry Your Password is Incorrect");
		}
	}
	else
	{
		printf("Sorry Your Username is Incorrect");
	}
	
	getch();
}
							
							
Share Share on Facebook Share on Twitter Share on LinkedIn Pin on Pinterest Share on Stumbleupon Share on Tumblr Share on Reddit Share on Diggit

You may also like this!