What is control statements in C?
Control statements are used in C or other programming language to regulate the flow of program execution, i.e., whether or not a set of statements will be executed based on certain conditions or how many times a certain block of cedes is to be executed, again based on condition.
For Example:
/*Control statements in C*/
int x = 2;
int y = 3;
/*If condition is true, this code block will be executed*/
if((x + y) % 5 == 0){
// Do whatever
}
/*if condition is false, this code block will be executed*/
else{
//Do something else
}
-------------------OR----------------------------
int i;
for(i = 0; i < 10; i++){
/* Do anything that you want. This code block will be
* executed until i becomes > or = to 10 */
}
There are three type of control statements in C
Decision making statement:
It is used to decide whether a certain statement or block of statements will be executed or not i.e. If a certain condition is true then a block of statement is executed otherwise not.
Types of decision making statement:
- Simple if statement
- if...else & ladder if...else statement
- nested if...else statement
- Switch...case statement
Iterative statements:
Iterative statements create loops in the program. It is the process where a set of instructions or statements is executed repeatedly for a specified numbers of time or until a condition is satisfied.
Type of iteration statement in C:
Jumping statement in C:
Jump statement are used to transfer control from one point to another point in the program. It allows to exit loop, start the next iteration of a loop and explicitly transfer program control to a specified location in you program.
Type of jumping statement:
0 Comments:
Post a Comment
Please don't enter any spam link in the comment box.