Types of Loops
- Count‑controlled loop — FOR…NEXT
- Pre‑condition loop — WHILE…ENDWHILE
- Post‑condition loop — REPEAT…UNTIL
FOR…NEXT Loop
- Repetition is known.
- Count‑controlled, fixed number of iterations.
- No condition required.
- Example:
FOR Count = 1 TO 10
// statements
ENDFOR
WHILE…ENDWHILE Loop
- Repetition is unknown.
- Conditional loop, checked before execution (pre‑condition).
- Loop runs until the condition remains true.
- Example:
Count = 0
WHILE Count < 10 DO
Count = Count + 1
ENDWHILE
REPEAT…UNTIL Loop
- Repetition is unknown.
- Conditional loop, checked after execution (post‑condition).
- Loop runs until the condition becomes false.
- Example:
Count = 0
REPEAT
Count = Count + 1
UNTIL Count = 10
Programming Techniques
- SUM — Used to calculate the total of values.
- COUNT — Used to calculate the number of items or iterations.
No comments:
Post a Comment