Introducing while loop in C. Simple program with detailed explanation.
(Similar post on while loop is here.)
(For Part 2 of this tutorial, see here.)

Introducing while Loop in C
Loops are used to execute a specific piece of code multiple times.

while (some condition)
{
// block of code
}

As long as the condition is true, the block of code within the while loop is repeatedly executed.

Q. Print “Good Morning” three times.

Solution
#include <stdio.h>
int main()
{
int i = 1;
while (i <= 3)
{
printf("Good Morning\n");
i++;
}
printf("Out of the loop now\n");
return 0;
}
Output
Good Morning
Good Morning
Good Morning
Out of the loop now

For a detailed explanation of the above program, please refer to the images above.

Posted in

2 responses to “Introducing while loop in C. C Programming Tutorial”

  1. […] Introducing while loop in C. C Programming Tutorial […]

    Like

  2. […] we shall look at an introduction to for loops in C. (For posts on while loops, pls see here. For posts on C Programming, pls see here.) We shall look at certain basic aspects of loop, and […]

    Like

Leave a comment

Is this your new site? Log in to activate admin features and dismiss this message
Log In