0% found this document useful (0 votes)
39 views5 pages

Dsa Notes of Class 03 by Manoj Kumar

The document discusses conditionals and loops in programming. It describes if, if-else, if-else-if statements for decision making. It also covers for, while, do-while loops used to repeatedly execute code. Specific examples are given for if, if-else-if, nested if, and for loops showing syntax, logic, and sample outputs.

Uploaded by

devilkapoor133
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views5 pages

Dsa Notes of Class 03 by Manoj Kumar

The document discusses conditionals and loops in programming. It describes if, if-else, if-else-if statements for decision making. It also covers for, while, do-while loops used to repeatedly execute code. Specific examples are given for if, if-else-if, nested if, and for loops showing syntax, logic, and sample outputs.

Uploaded by

devilkapoor133
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

CONDITIONALS AND LOOPS

29 August 2023 10:02

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

1. if STATEMENT Working of if Statement:

Syntax of if statement:

If (condition){
//statements
}

Program of if statement:

Output:

Statement inside of if block

Statement inside of if block


Output:

Statement inside of if block

2. If-else STATEMENT

Working of if-else Statement:


Syntax of if-else statement:

If (condition){
//codes in if blocks}
else{
//codes in else blocks
}

Program of if-else statement:

Output:

Statement inside of else block

Statements outside of if-else block


Output:

Statement inside of else block

Statements outside of if-else block

3. If-else-if ladder STATEMENT

Syntax of if-else-if ladder statement:

Working of if-else-if ladder Statement:


If (condition1){
//codes
}
else if(condition2){
//codes
}
else if(condition2){
//codes
}
.
.
else {
//codes
}

Program of if-else-if ladder


statement:
Output:

Statement inside of if block


Statement outside of if-else-if block

4. Nested if-else STATEMENT

Syntax of nested if-else statement: Program of nested if...else statement:

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:

for (initialization; conditions; updation)


{
Start Initialization Conditions Statements
// statements
}

End

Program of for loop:

Output:

Babbar = 0
Babbar = 1
Babbar = 2
Babbar = 3
Babbar = 4

Nested for loop

Syntax of nested for loop:

for (initialization; conditions; updation)


{ Patterns problem are best understanding
for (initialization; conditions; updation) to nested for loop
{
// statements
}
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy