Dsa Notes of Class 03 by Manoj Kumar
Dsa Notes of Class 03 by Manoj Kumar
Dsa Notes of Class 03 by Manoj Kumar
https://www.linkedin.com/in/manojoffcialmj/
CONTROLS STATEMENTS:
Decision Making in programming is similar to decision making in real life. In programming too, we face some situations where we
want a certain block of code to be executed when some condition is fulfilled.
Selection statements:
• if
• if-else
• if-else-if
• nested-if
• switch-case
• Ternary operator
Syntax of if statement:
If (condition){
//statements
}
Program of if statement:
Output:
2. If-else STATEMENT
If (condition){
//codes in if blocks}
else{
//codes in else blocks
}
Output:
If (condition1)
{
if(condition2)
{
//if codes
}
else
{
//else codes
}
}
else
{
//codes
}
Output:
Statement inside of nested else block
Statement inside of if block
Statement outside of if-else and nested if-else block
LOOPS:
Looping in programming languages is a feature that facilitates the execution of a set of instructions/functions repeatedly
while some condition evaluates to true.
C++ provides three ways of executing the loops. While all the ways provide similar basic functionality, they differ in their
syntax and condition checking the time.
Java's loops:
• for loop
• while loop
• do while loop
• for each loop
1. for loop
Working of for loop:
Updation
Syntax of for loop:
End
Output:
Babbar = 0
Babbar = 1
Babbar = 2
Babbar = 3
Babbar = 4