0% found this document useful (0 votes)
17 views8 pages

Control - Structures - Loops - Conditionals Part 9

Control structures are fundamental in programming, determining the flow of execution through conditional statements and loops. Conditional statements, such as if, if-else, and switch, enable decision-making, while loops (for, while, do-while) facilitate repeated execution of code blocks. Mastering these structures enhances problem-solving capabilities in programming.

Uploaded by

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

Control - Structures - Loops - Conditionals Part 9

Control structures are fundamental in programming, determining the flow of execution through conditional statements and loops. Conditional statements, such as if, if-else, and switch, enable decision-making, while loops (for, while, do-while) facilitate repeated execution of code blocks. Mastering these structures enhances problem-solving capabilities in programming.

Uploaded by

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

2.

3 Control Structures (Loops,


Conditionals)
Understanding Control Flow in
Programming
What are Control Structures?
• Control structures determine the flow of
execution in a program.

• Types of Control Structures:


• - Conditional Statements (if, if-else, switch)
• - Loops (for, while, do-while)
Conditional Statements
• Conditional statements allow a program to
make decisions based on conditions.

• - if statement: Executes a block of code if a


condition is true.
• - if-else statement: Executes one block if true,
another if false.
• - switch statement: Selects a case based on a
variable’s value.
Example: if-else Statement
• Python:
• age = 18
• if age >= 18:
• print('You are an adult')
• else:
• print('You are a minor')

• Java:
• int age = 18;
• if (age >= 18) {
• System.out.println('You are an adult');
• } else {
• System.out.println('You are a minor');
• }
Loops in Programming
• Loops allow repeated execution of a block of
code.

• Types of Loops:
• - for loop: Iterates a fixed number of times.
• - while loop: Repeats as long as a condition is
true.
• - do-while loop: Executes at least once before
checking the condition.
Example: for Loop
• Python:
• for i in range(5):
• print('Iteration:', i)

• Java:
• for (int i = 0; i < 5; i++) {
• System.out.println('Iteration: ' + i);
• }
Example: while Loop
• Python:
• count = 0
• while count < 5:
• print('Count:', count)
• count += 1

• Java:
• int count = 0;
• while (count < 5) {
• System.out.println('Count: ' + count);
• count++;
• }
Conclusion
• Control structures are essential for directing
program execution.

• - Conditional statements help in decision-


making.
• - Loops allow repetitive execution of tasks.
• - Mastering these structures improves
problem-solving skills.

You might also like