C CONTROL STATEMENTS
Control Statements in C language enable to determine flow of program using various kind of statement.In c language mostly program executed by sequence but control statements can change flow of program by making jump within program.
3 Types of Control Statements are
Decision Making Statements:- This Statements is also called conditional statements.In C language normally program executes in sequence but some times there are number of situation where programmer needed to change the sequence .This involved decision making to see whether particular condition is true or not.
Decision Making Statements support following statements:-
1.If Statement
2.If else Statement
3.If else if Statement
4.Nested if Statement
5.Switch Statements
1.If Statement:- In C is used to if statements to control the program flow based on the condition. if statement is used to check the one or more condition.And In C if statements tests the condition. It executes the if block if condition is true.
Syntax
if(condition)
{
//code to be executed
}
if statements flow chart
2.If-else statements:- The C if-else statement tests the condition.It execute the block if condition is true otherwise else block is executed.we can perform two operation in a single condition. that is one is for the true of that condition, and other for the false of the condition.both block are cannot be executed in simantansouly.
Syntax:-
if(condition)
{
//code to be executed if condition is true
}
else
{
//code to be executed if condition is false
}
if-else statement flow chart
3.If else-if statement:-The if-else-if statement execute one condition from multiple statements.
Syntax:-
if(condition 1)
{
//code to be executed if condition is true
}
else if(condition 2)
{
//code to be executed if condition is true
}
else if (condition 3)
{
//code to be executed if condition is true
}
else
{
//code to be executed if all the condition are false
}
flow chart of if else-if statement
4. Nested if statement:- The nested if statements represents the if block within another if block. the nested block condition executes only when outer if block condition is true.
syntax:-
if(condition)
{
//code to be executed
if(condition)
{
// code to be executed
}
}
5.Switch Statement
The switch statements execute one statements from multiple condition.
Rules of switch statement
ππ» Switch expression and case value must be integer and character type.
ππ»Case value must be consider within switch statement.
ππ»The break statement in switch case is not must it is optional.
Syntax:-
switch(expression)
{
case value 1:
//code to be executed;
break;
case value 2:
//code to be executed;
break;
case value 3;
//code to be executed;
break;
.......
default:
//code to be executed if all cases are not matched;
}
Flow chart of switch statement
Switch Statement is Fall Through:- Without break statement all the statements are executed this condition is called fall through.
Syntax:-
switch(expression)
{
case value 1:
//code to be executed;
case value 2:
//code to be executed;
.......
default:
//code to be executed if all cases are not matched;
}
NEXT STATEMENT AVAILABLE SOON AS......
Control Statements in C language enable to determine flow of program using various kind of statement.In c language mostly program executed by sequence but control statements can change flow of program by making jump within program.
3 Types of Control Statements are
Decision Making Statements:- This Statements is also called conditional statements.In C language normally program executes in sequence but some times there are number of situation where programmer needed to change the sequence .This involved decision making to see whether particular condition is true or not.
Flow Chart Of Decision Making Statements |
Decision Making Statements support following statements:-
1.If Statement
2.If else Statement
3.If else if Statement
4.Nested if Statement
5.Switch Statements
1.If Statement:- In C is used to if statements to control the program flow based on the condition. if statement is used to check the one or more condition.And In C if statements tests the condition. It executes the if block if condition is true.
Syntax
if(condition)
{
//code to be executed
}
if statements flow chart
Flow chart of if statements |
2.If-else statements:- The C if-else statement tests the condition.It execute the block if condition is true otherwise else block is executed.we can perform two operation in a single condition. that is one is for the true of that condition, and other for the false of the condition.both block are cannot be executed in simantansouly.
Syntax:-
if(condition)
{
//code to be executed if condition is true
}
else
{
//code to be executed if condition is false
}
if-else statement flow chart
3.If else-if statement:-The if-else-if statement execute one condition from multiple statements.
Syntax:-
if(condition 1)
{
//code to be executed if condition is true
}
else if(condition 2)
{
//code to be executed if condition is true
}
else if (condition 3)
{
//code to be executed if condition is true
}
else
{
//code to be executed if all the condition are false
}
flow chart of if else-if statement
4. Nested if statement:- The nested if statements represents the if block within another if block. the nested block condition executes only when outer if block condition is true.
syntax:-
if(condition)
{
//code to be executed
if(condition)
{
// code to be executed
}
}
5.Switch Statement
The switch statements execute one statements from multiple condition.
Rules of switch statement
ππ» Switch expression and case value must be integer and character type.
ππ»Case value must be consider within switch statement.
ππ»The break statement in switch case is not must it is optional.
Syntax:-
switch(expression)
{
case value 1:
//code to be executed;
break;
case value 2:
//code to be executed;
break;
case value 3;
//code to be executed;
break;
.......
default:
//code to be executed if all cases are not matched;
}
Flow chart of switch statement
Switch Statement is Fall Through:- Without break statement all the statements are executed this condition is called fall through.
Syntax:-
switch(expression)
{
case value 1:
//code to be executed;
case value 2:
//code to be executed;
.......
default:
//code to be executed if all cases are not matched;
}
NEXT STATEMENT AVAILABLE SOON AS......
Comments
Post a Comment