Loops

A loop is a sequence of instructions that is continually repeated until a certain condition is reached. It is a fundamental programming idea that is commonly used in writing programs. If a programmer wants to perform a specific multiple times then he uses a loop.

There are different types of loops we have in programming :

  • While loop is a loop that repeat the statement in the loop body. Before executing the loop body its test the condition for true or false.
  • Do… while loop is like while loop but its test the condition after executing the loop body.
  • For loop is when we have an option of incrementing and decrementing outside the loop body.
  • For each loop is a loop that applies a function to the range of elements in a collection .
  • Nested loops is when using one or more loops inside a loop.
Advertisements