Shohan
Shohan
Presenters
MD. Shohan Rony ID: 232-35-436
MD. Ashri Jamil Sazin ID: 232-35-793
Understanding Loops
in C Programming
Loops are a foundational concept in C
programming. They enable repetitive execution
of code blocks. Loops are essential for efficient
and concise code. This presentation will provide
a comprehensive guide to understanding and
using loops effectively.
What is loop?
With Loop:
for (int i = 1; i <= 10; i++)
{ printf("%d\n", i); }
Types of loop in c
Condition
Evaluated before each iteration. The loop continues if true.
Increment/Decrement
Executed after each iteration.
Initialization
Done before the while loop.
2
Condition
Evaluated before each iteration.
1
3 Increment/Decrement
Done within the loop body.
int i = 0;
while (i < 5) {
printf("Iteration: %d\n", i);
i++;
}
The do-while Loop
Condition
Evaluated after each iteration.
Guaranteed Execution
Ensures at least one execution.
int i = 0;
do {
printf("Iteration: %d\n", i);
i++;
} while (i < 5);
For Loop: Condition check before execution, used when iterations are known.
While Loop: Condition check before execution, used when iterations are
unknown.
Do-While Loop: Condition check after execution, ensures at least one execution.
Nested Loops
Transfers Control
Goes to the next statement.
Proceeds
Goes to the next iteration.
The code prints only odd numbers. A common use is skipping specific
cases within a loop.
Conclusion
Any questions?