Repetition Control Structures
Repetition Control Structures
First Semester
2024/2025
1
ELE2309 COMPUTER PROGRAMMING 2024/2025
Learning Objectives
Definition:
• Similar to the while loop but guarantees execution at least once.
• The condition is checked after the execution of the loop body.
Syntax:
do {
// Code to execute
} while(condition);
Example:
int i = 1;
do {
cout << "Iteration " << i << endl;
i++;
} while(i <= 5);
Loop Control Statements
1. break Statement
• Terminates the loop execution immediately.
Example:
for(int i = 1; i <= 5; i++) {
if(i == 3) break;
cout << i << endl;
}
2. continue Statement
• Skips the current iteration and moves to the next one.
Example:
for(int i = 1; i <= 5; i++) {
if(i == 3) continue;
cout << i << endl;
}
Choosing the Right Loop