hot post

while loop in c programming example part 1 || #learn c programming

while loop in c programming example part 1 || #learn c programming
while loop in c programming example


while loop in c programming example


Today we talk about while loop in c programming. Before this, we have studied about the condition operator in great detail. If you do not know anything about the conditional operator, then you have to click on the conditional operator to read it first. If you have read about the conditional operator, now we start the while loop in c programming.


What is loop in c

 Easy definition:  The statement of Loop keeps repeating until the satisfaction of a condition is achieved.


Why we use loop in c programming?

When we create a program in C language, if you want to print the same thing repeatedly or want to print any word or count one by one. Or want to print any name more than once. So the number of times we have to print the name, we will have to use printf (), which will make the program much longer and memory too wasted. To avoid all these things, loop in C language has been provided so that you can easily create programs and save memory. With the help of loops you can easily execute the same statement again and again. . There are different types of loops arranged in C, and each type of loop provides a block, in which that statement is written. Which you want to execute in the program more than once.

The loop consists of three things.

1. Initial Variable: -  This is a variable from where you start the loop. This is an integer variable, this variable is used till then. Unless the condition inside the loop is false, this variable is included in the condition of the loop.  


2. Condition: -  This is the condition which controls the loop. As long as this condition remains true, the loop continues to execute. The loop terminates as soon as the condition becomes false.


3. Increment / Decriment: -  How many numbers or how much you want to increment / decrypt the initial variable / condition. It is defined in the increment / decision part.


Type of loop in c

There are the following types of C Loops.

  • while loop
  • do-while loop
  • for loop
  • nested loop


What is While loop in c programming

While Loop: -  While Loop is a simple loop, it is executed as long as the condition is true. This loop terminates when the condition is false. If the condition is false at first, then the compiler is not entered in the loop. The loop is grossly skipped.

Syntax: -

initial variable declares;

while(condition)

{

//statement;

//increment /decrement; 

}

Now let’s take some example for better understanding


Example: 1

Now, I will print my name 5-time whit the help of while loop. So, see coding very carefully: 


while loop in c programming example part 1 || #learn c programming

Output

Virender sahu

Virender sahu

Virender sahu

Virender sahu

Virender sahu


Example: 2

Now, I will print numbers

while loop in c programming example part 1 || #learn c programming

Output

1

2

3

4

5

 If you understood the while loop in c programming , please comment and answer yes or not, now we cover the remaining loops type in the next post.


Also read

(conditional-operators-in-c-programming)

(if-else-statement-in-c-programming.)


Thanks for reading this post


Post a Comment

0 Comments