Loops Structure
Loops Structure
PRESENTATION
Loops structure
GROUP 3
Presented By:
1-Muhammad Zain
2-Saifullah Khan
Presented to:
Mam Kinza Noor
WHAT ARE LOOPS
• Loops in C are used to repeat a task multiple times without having to write the same
code again and again. They help in saving time, making the program shorter, and
easier to manage.
• For example:
If you want to print "Hello" 5 times then instead of writing:
• printf("Hello\n");
• printf("Hello\n");
• printf("Hello\n");
• printf("Hello\n");
• printf("Hello\n");
HOW THEY WORK ?
• You can use loop:
1.For Loop: Used when you know how many times to repeat.
2.while Loop: Used when you want to repeat until a condition is
true.
3.Do While Loop Similar to while, but ensures the code runs at least
once.
• Loops make Programing simple and efficient
UNDERSTANDING WHILE
LOOP
• A while loop in C is a way to repeat a group of instructions over and over, as long
as a certain condition is true.
• Think of it like this:
• If you have a task to do repeatedly, a while loop can help you do it automatically
• Syntax:
• while (condition)
• {
• // Body of the Loop
• }
FLOWCHART OF WHILE LOOP
HOW DOES IT WORK
1.The computer checks a condition (e.g., "Is the number less
than 5?").
2.If the answer is yes, it runs the code inside the loop.
3.After running the code, it checks the condition again.
4.This continues until the condition is false, and then the loop
stops.
PROGRAM
• #include <stdio.h>
• int main()
• {
• int i = 0;
• while (i < 5)
• {
• printf("Number: %d\n", i);
• i++;
• }
•}
ADVANTAGES OF WHILE
LOOP
• The while loop is advantageous when:
• You need repeated actions with undefined repetitions.
• You want to perform a task only if a condition is true.
• You prefer a clean and simple structure for repetitive tasks.
WHAT IS DO WHILE LOOP ?
• A do-while loop in C is a control structure that allows you to
execute a block of code at least once, and then repeat it as long as
a given condition is true.
• Syntax:
• do
•{
• // Body of the loop
• } while (condition);
FLOWCHART OF DO WHILE
LOOP
HOW DOES IT WORKS