UrbanPro

Learn C Language from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Search in

Why is while loop used if the work can be done more efficiently by a for loop in C programming language?

Asked by Last Modified  

Follow 3
Answer

Please enter your answer

Programming World

For loops (and for each loops especially) are definitely more common, but sometimes you just need a while loop to get the job done. for loop is 'counter-controlled loop' where as while loop if you were making a game and needed to make the game loop over and over, you could use a while loop that would...
read more
For loops (and for each loops especially) are definitely more common, but sometimes you just need a while loop to get the job done. for loop is 'counter-controlled loop' where as while loop if you were making a game and needed to make the game loop over and over, you could use a while loop that would run infinitely by using. while (i = 1) { //your logic } read less
Comments

for loops basically is used when developer knows number of iterations to be performed is known already : Example : printing table of 10 up to 10 i.e 10 * 10=100 we know number of iteration=10 so for loop can be used for(i=1;i<=10;i++){ printf("%d \n",i); ...
read more
for loops basically is used when developer knows number of iterations to be performed is known already : Example : printing table of 10 up to 10 i.e 10 * 10=100 we know number of iteration=10 so for loop can be used for(i=1;i<=10;i++){ printf("%d \n",i); // already knew iteration=10 so for loop } WHILE loop on other hand is used if developer s not sure or uncertain about number of iterations prior. Example C program to reverse the number : here number n can be anything inputted by user so developer is not sure about number of iteration so while loop while(n != 0) { remainder = n%10; reversedNumber = reversedNumber*10 + remainder; n /= 10; } we can solve this by using for loop also but it is recommended if number of itertion not know use WHILE else if known then FOR. read less
Comments

IT Professional

There is no difference semantically in both the constructs. For is easy to use. While can be used for the same purpose and vice versa with for loop is true. It depends on choice and of course some specific cases where you can avoid cryptic code. All loops of for can be replaced with while and vice versa,...
read more
There is no difference semantically in both the constructs. For is easy to use. While can be used for the same purpose and vice versa with for loop is true. It depends on choice and of course some specific cases where you can avoid cryptic code. All loops of for can be replaced with while and vice versa, given we'll have to define some variables such as counters etc. read less
Comments

View 1 more Answers

Related Questions

What is meant by “enum” in C?
An enum is a keyword in C language, it is an user defined data type. All properties of integer are applied on Enumeration data type It work like the Integer.
Geetanjali
Which is the best book for understanding concepts of c language?
One highly recommended book for understanding the concepts of the C language is "C Programming Absolute Beginner's Guide (3rd Edition)" by Perry and Miller. This book is well-suited for beginners and provides...
Chetana
0 0
7
How do I get C help in Ubuntu?
Use command line tool 'man'. for example 'man printf' will give you details regarding printf function C
Ashmita
0 0
5
Is C destined to die?
No not at all
Anubhav
0 0
5

What is C language?

It is a general purpose high level language used to make software for operating systems (kernel programms), game development, Embedded devices etc. It avoids the complexity of writing machine code and...
Shiva

Now ask question in any of the 1000+ Categories, and get Answers from Tutors and Trainers on UrbanPro.com

Ask a Question

Related Lessons

4 Things Every Tech Startup Needs to Know About The Coaching Industry
Knowledge on any subject is widely available to those who wish to learn. However, just gathering knowledge from other people doesn’t guarantee results in business. Results come from applying what...

C Program-Vowels and Consonants
/*WAP to print the character entered by user is a vowel or consonant*/ //Header files #include<stdio.h>#include<conio.h> //Main functionvoid main(){ char c; //Function for clearing screen...

Datatypes in C Language
Data types in C Language Data types specify how we enter data into our programs and what type of data we enter. C language has some predefined set of data types to handle various kinds of data that...


What is a Programming Language
What is a Language? Language is a communication system of human. What is a programming Language? A programming Language is a formal constructed language design to communicate...

Looking for C Language Classes?

Learn from the Best Tutors on UrbanPro

Are you a Tutor or Training Institute?

Join UrbanPro Today to find students near you
X

Looking for C Language Classes?

The best tutors for C Language Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Learn C Language with the Best Tutors

The best Tutors for C Language Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more