DEV Community

bhuvaneswari nandhagopal
bhuvaneswari nandhagopal

Posted on

loops

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

  1. for loop
  2. 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:

  1. i = 1 → start value
  2. i <= 5 → condition
  3. print number
  4. increase i by 1
  5. repeat until condition becomes false

Top comments (0)