📌 Iteration in Programming
Iteration refers to the process of executing a set of instructions repeatedly until a certain condition is met. It is commonly implemented using loops.
1️⃣ Types of Iteration (Loops)
(a) Entry-Controlled Loops (Condition checked first)
🔹 For Loop → Used when the number of iterations is known.
🔹 While Loop → Used when the number of iterations is not known in advance.
(b) Exit-Controlled Loop (Condition checked after execution)
🔹 Do-While Loop → Executes at least once before checking the condition.
2️⃣ Iteration Using Loops in C
📌 (a) For Loop (Definite Iteration)
🔹 Output:
📌 (b) While Loop (Indefinite Iteration)
🔹 Used when the number of repetitions is unknown beforehand.
📌 (c) Do-While Loop (Execute at Least Once)
🔹 Executes at least once, even if the condition is false.
3️⃣ Iteration in Arrays (Traversing Elements)
🔹 Iterates through an array using a loop.
4️⃣ Infinite Loops (Use with Caution!)
🔹 Use break
to exit an infinite loop.
No comments:
Post a Comment