answersLogoWhite

0

What is the while loop in C programming?

Updated: 8/10/2023
User Avatar

Ankitakushte

Lvl 1
15y ago

Best Answer

"while" is an entry controlled loop statement i.e the condition is evaluated first and if it is true the body of the loop is evaluated.This process is repeated until the test condition is false;then the control is transfered out of the loop.

The general form of while is as following

syntax:

while (<condition>)

{

<statements>;

}

User Avatar

Wiki User

13y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

12y ago

While loop is one of the type of loops that C language offers, they are usually used when you are not concerned about the number of iterations a loop will follow. For

example:

char choice='y';

while(choice=='y')

{

scanf("%c",&chocie);

}

the above code will work while the user enters y

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

Well, the for loop and while loop are equivalent, in that you can use them both to do the same things. The difference is mainly syntactic. A for loop should be used to progress through a sequence, where there is a clear initialization, end test, and increment at each step through the loop, for example, to loop through the elements of an array or set. The while loop should be used when there isn't a clear progression, for example, to loop over input until the input is done.


the basic difference is that for loop is used when fixed iterations have to be performed whereas while loop is used when the number of times the loop construct is to be performed is not known..

This answer is:
User Avatar

User Avatar

Wiki User

6y ago

for loop is suitable for situations when we know in advance how many times the loop will continue but while loop is suitable for situations when we don't know how many times the loop will iterate.

For example:

Display all the numbers from 1 to 10. here we know in advance the loop will continue 10 times , so for is suitable.

Count number of bits set to 1 in an integer 375. here in advance we don't know is the binary of 375 and how many bits are set 1, so while loop is suitable here.

This answer is:
User Avatar

User Avatar

Wiki User

15y ago

The "while" loop is a function built-in C language which allows you to loop certain piece of code until the criteria is met instead of retyping the code all over again. For example, this is C# thought (similar concept, different syntax): string userInput = "0"; - define the variable to something else other than 'end' so the while loop executes the first time!

while(userInput != "end")

{

Console.WriteLine("The look will continue to print this text unless you type the word 'end' at the prompt!");

Console.WriteLine("Enter text: ");

userInput = Console.ReadLine();

}

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

while (expression) statement

do statement while (expression)

In the first form, expression is evaluated. If true, statement is executed and the loop repeats from the evaluation step. In the second form, statement is executed and then expression is evaluated. If true, the loop repeats from the statement step.

This answer is:
User Avatar

User Avatar

Wiki User

15y ago

If you need to do something with repeation (calculating sums, integrals, adding users in the data base...) you have to use for or while loop.

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

I could give you the syntax of the while-statement, but it wouldn't help you. Please go and buy a good text-book.

while ()

This answer is:
User Avatar

User Avatar

Wiki User

6y ago

A while loop iterates over the same code block until the control expression evaluates false.

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

Both of them is usable in C.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is the while loop in C programming?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Which loop is also called an exit-condition loop in C programming?

The do while loop is also called an exit condition loop in c, c++, and java.


What is the definition of 'nested' in C programming?

In C a structure within a structure is called nested. For example, you can embed a while loop in another while loop or for loop in a for loop or an if statement in another if statement.


What are the Rules associated with for loop in C programming?

There are no "Rules", you only have to remember the syntax:for (; ; ) it is the same thing as:;while () {;}


How infinite loop is created using while in C programming?

while (2*2==4) printf ("Still running\n");


How can you define null statement in loop in C programming?

If you are using for loop for(;;); or you can also define condition and iterations but the loop has to close there itself without any statement inside it. In the similar way you can define while and do while loop without any statement.


How do you use loop in C programming?

#include&lt;stdio.h&gt;


How many rows do the update queries fetch inside a while loop?

Is your question about C programming or Oracle Database. From the stand point of C programming your question does not make sense. Perhaps you need to rephrase the question.


What is difference between select Case statement and nested loop in c programming in UNIX?

UNIX has no bearing on the C language; it is cross-platform. There is no select/case in C, you probably meant switch/case. However, a switch/case is a conditional jump while a nested loop is a loop within a loop. Besides the C language they have nothing in common with each other.


What is the Difference between while and do while?

Both are programming commands. A do/while loop will execute at least once. A while loop may not execute at all.


What is a loop type?

A Loop is a programming language construct that instructs the processor to repeat a sequence of operations a number of times until a specific condition is reached. There are different types of loops. They are: * for loop * while loop * do while loop


What is a dowhile statement in C programming?

"do statement while (...);" is a loop which does at least one iteration even if the condition after while is false. When, for instance, "while(...) statement" does not iterate at all if the condition after while is false.


Is do while loop in c is exit controoled loop?

yes