If we look at the table printing program, we’ll notice that we’re repeating a similar kind of instruction with some changes in each instruction. Instead of writing the same instruction repeatedly, we can avoid rewriting the code using repetition statements.

To repeat a piece of code (set of statements), almost every programming language offers loops. Using loops, our work becomes a lot easier and more manageable.

We will learn about two types of loops, the while loop and the for loop.

The while loop

The syntax of the while loop is as follows:

Get hands-on with 1200+ tech skills courses.