The control strucures are the statements that are used to alter the flow or sequence of excecution of program.
There are basically two types of control strucures:
1. Decision making statements
a) if statement
b) if -else statement
c) switch statement
2. Loop constructs:
a) for loop
b) while loop
c) do-while loop
We will also study about break, continue and go to in subsequent lectures
Here we will cover if statement.
Firatly u need to know the symbols for various conditions they are called relational operators.
1. == means here "equal to "
2. <= means here "less than Or equal to"
3. >= means here "greater than Or equal to"
4. ! = means " Not equal to"
Now u are euipped enough to learn loops.
Let's begin with the if statement
If statement:
The if statement is used to excecute the code if certain condition is true.
General from of if statement is
If(condition)
{
Statements
}
The flow chart of if else statement is as follows
If the condition is false then the program simply runs after skipping the if statement.
If the condition is false then the program simply runs after skipping the if statement.
Let's take a simple code to check if the number is divisible by 10.
![]() |
Source code. |
![]() |
The statement is not printed which means that our input no. Is not divisible by 10. So the condition is false. Now let's see what's the output if the condition is true. |
Let's see the output.
The condition is true so the statement got printed.
Conclusions:
Uve learnt about the working of if statement and are ready to use it.
Did u find it interesting?
Comments
Post a Comment