V.V.P Engineering College Computer Programming & Utilization
Chapter No: 3 Structure of C
Control Structure in C
CHAPTER NO: 3 Control Structure in C
Mentioned
1 Explain simple if statement with example.
2 Explain if-else statement with example.
topics in
3 Explain nested if with example.
4 Explain ladder if-else with example.
the 5 Explain switch statement with suitable example.
document6 Explain goto statement.
7 Explain while loop with example.
8 Difference between entry control and exit control (while and do-while).
9 Explain do while loop with example.
10 Explain for loop with example.
11 What is nested loop?
12 Explain break and continue statement with example.
Q-1 Explain simple If Statement with example.
Answer:
When we have situation to check some conditions ans based on that condition some statements
will be executed then we can use if statement.
Syntax:
If(<Condition>)
{
True
False //Statement block;
}
Next Statement;
Chapter no: 3
, V.V.P Engineering College Computer Programming & Utilization
Here, first condition is checked. If condition becomes true then statement inside if block will be
executed.
If condition becomes false then statement outside if block will be executed.
We can also put more than one condition to check through if statement.
True Condition False
Statement Block Next Statement
If statement is executed in following order:
1) First condition is checked.
2) If condition is true then statement block is executed first and then next statement
will be executed
3) If condition is false then next statement outside if block will be executed.
Example:
#include<stdio.h>
#include<conio.h>
Note:
void main()
Every statement in C {
ends with semicolon int var;
(;) but if statement printf(“\n enter the value of the variable”);
does not end with scanf(“%d”,&var);
semicolon. if(var<=100)
When we want to
printf(“\n the value entered is less than 100”);
execute multiple
printf(“program is over”);
statements, then {} is
}
compulsory,
otherwise not
compulsory.
Q-2. Explain if else statement with example.
Answer:
Chapter no: 3
, V.V.P Engineering College Computer Programming & Utilization
When we have situation to execute some statement if condition becomes true and other
statement if condition becomes false then we can use if else statement.
Syntax:
If(<Condition>)
True {
//Statement block1;
} False
else
{
//Statement block2;
}
Here first condition is checked first, if it becomes true then statement block1 will be executed and
if condition becomes false then statement block2 will be executed.
True False
Condition
Statement Block 1 Statement Block2
If else statement is executed in following order:
1) First condition is checked.
2) If condition is true then statement block1 is executed.
3) If condition is false then statement block2 inside else block will be executed.
Chapter no: 3
Chapter No: 3 Structure of C
Control Structure in C
CHAPTER NO: 3 Control Structure in C
Mentioned
1 Explain simple if statement with example.
2 Explain if-else statement with example.
topics in
3 Explain nested if with example.
4 Explain ladder if-else with example.
the 5 Explain switch statement with suitable example.
document6 Explain goto statement.
7 Explain while loop with example.
8 Difference between entry control and exit control (while and do-while).
9 Explain do while loop with example.
10 Explain for loop with example.
11 What is nested loop?
12 Explain break and continue statement with example.
Q-1 Explain simple If Statement with example.
Answer:
When we have situation to check some conditions ans based on that condition some statements
will be executed then we can use if statement.
Syntax:
If(<Condition>)
{
True
False //Statement block;
}
Next Statement;
Chapter no: 3
, V.V.P Engineering College Computer Programming & Utilization
Here, first condition is checked. If condition becomes true then statement inside if block will be
executed.
If condition becomes false then statement outside if block will be executed.
We can also put more than one condition to check through if statement.
True Condition False
Statement Block Next Statement
If statement is executed in following order:
1) First condition is checked.
2) If condition is true then statement block is executed first and then next statement
will be executed
3) If condition is false then next statement outside if block will be executed.
Example:
#include<stdio.h>
#include<conio.h>
Note:
void main()
Every statement in C {
ends with semicolon int var;
(;) but if statement printf(“\n enter the value of the variable”);
does not end with scanf(“%d”,&var);
semicolon. if(var<=100)
When we want to
printf(“\n the value entered is less than 100”);
execute multiple
printf(“program is over”);
statements, then {} is
}
compulsory,
otherwise not
compulsory.
Q-2. Explain if else statement with example.
Answer:
Chapter no: 3
, V.V.P Engineering College Computer Programming & Utilization
When we have situation to execute some statement if condition becomes true and other
statement if condition becomes false then we can use if else statement.
Syntax:
If(<Condition>)
True {
//Statement block1;
} False
else
{
//Statement block2;
}
Here first condition is checked first, if it becomes true then statement block1 will be executed and
if condition becomes false then statement block2 will be executed.
True False
Condition
Statement Block 1 Statement Block2
If else statement is executed in following order:
1) First condition is checked.
2) If condition is true then statement block1 is executed.
3) If condition is false then statement block2 inside else block will be executed.
Chapter no: 3