INTRODUCTION TO LOOP:
A loop is used to repeat the same code many times.
We use loops for repeated work in programming.
TYPES OF LOOP
- for loop
- while loop
FOR LOOP:
- Used to repeat code a fixed number of times.
- Mostly used with range or collection.
what is range?
- Used to create a sequence of numbers.
- Mostly used in loops.
what is collection?
- Collection is a data type used to store multiple values in a single variable.
WHILE LOOP:
- A while loop is used to repeat code again and again while the condition is true
Simple Explanation:
- i = 1 → start value
- i <= 5 → condition
- print number
- increase i by 1
- repeat until condition becomes false
Top comments (0)