Sitemap

Loops (Programming Fundamentals part-5)

2 min readApr 29, 2026

--

Press enter or click to view image in full size

Let me ask you something interesting before learning about loops. Do you like doing same thing again and again? Do you like to study same topic for 12 hours straight or would you like it if I tell you to fill a bucket with water but one single drop at a time and do nothing else until it’s done. Probably not Right! It may sound a bit scary. Actually, it is scary, but we have to do it in programming and in fact many times BUT there is a catch to it.

Let's understand loops

Let's say for some unknown reason you want to create a program that say “I love you” a hundred times. How would you do that? That's where loops come into play.

if loops were not there you would have to write printf("I LOVE YOU") a hundred times but with loops you can do it in very few lines. I will use C for explaining

int i = 1;
while(i<101){
printf("I LOVE YOU");
i++;
}

In this code above we are saying that run the code in block until i is not bigger than 101. Block of code will run till the condition mentioned in () is true. When it becomes false it stops.

Get Pixel and Code’s stories in your inbox

Join Medium for free to get updates from this writer.

Explaining in steps for better understanding:

  1. Creating a variable i and assigning it value 1.
  2. Creating a while loop.
  3. Adding condition to check if i is smaller than 101.
  4. Writing printf("I LOVE YOU") in code block.
  5. Writing i++ to add 1 in i every time it runs. Firstly, i is 1 as we declared. Loop runs for the first time it becomes 2. After second turn it becomes 3. When i becomes equal to 101 the code of block no longer runs because i is no longer smaller than 101. It is equal now.

There are other types of loops like for, do while. We will do it some other day when we learn C. Today we are only learning fundamentals of all programming language.

--

--

Pixel and Code
Pixel and Code

Written by Pixel and Code

0 followers

Pixel and Code teach programming in very simple language, explaining concepts like you are 5 years old to make coding easy and fun for everyone.