Loop: Beginning

Assalamu Alaikum. Hope you all are well by the grace of Almighty ALLAH. Today we learn about the loop in C programming.

In every programming language, thus also in the C programming, there are circumstances were you want to do the same thing many times. For instance, you want to print the same words ten times. You could type ten printf function, but it is easier to use a loop. The only thing you have to do is to setup a loop that execute the same printf function ten times.

There are three basic types of loops which are:

  • for loop
  • while loop
  • do while loop

The for loop:

The for loop uses the following structure:




A single instruction can be placed behind the for loop without the curly brackets.


The while loop:


The while loop uses the following structure:


  • The simplest of all looping structures is the while statement.
  • The while loop is an entry control loop.


The do while loop:


The do while loop is almost the same as the while loop. The do while loop has the following form:



  • There is a semicolon behind the while line.

We ca easily compare these loops by a simple program. Let's look at the program.


Thank you all...:)




0 comments:

Post a Comment