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

Is C destined to die?
No not at all
Anubhav
0 0
5
How do I get 6 power 13 in c language?
In the C programming language, you can calculate the power of a number using the pow() function from the <math.h> library. To find 6 raised to the power of 13, you would write a C program that includes...
Raju
0 0
6
hi sir c progarm codeing how to write sir........
take any C book then u can learn more...
Suryateja
What is the difference between ++var and var++?
First one is present increment and second one is the post incremental t of the variable. Both increases value of var to one. The difference between pre and post increment is given in below example. Int...
Chittaranjan
Can you assign a different address to an array tag?
Nope, because Array Tag/Name is an alias or name to the first location of the array. It doesn't have any memory of its own (pointers do have their own memory).
Sivaganesh
0 0
6

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

Ask a Question

Related Lessons

Everything about printf in C language
What is printf and from where it comes from in C code.? You must have used printf so many times in your Car programs but do you really know everything about printf? Let's see. What is the full form...

Internet of Things, Social Media Becoming Part of E-Discovery Landscape
The days when e-discovery consisted of handing over copies of e-mails to address Freedom of Information Act (FOIA) requests, compliance regulations or other legal obligations are over. Now, it's just as...

Recursion in C Programming
The process of calling a function by itself is called recursion and the function which calls itself is called recursive function. Syntax of Recursive Function returntype recursive_func () { statements; ...
R

Ravindra Yadav

2 0
0

How do i get best Campus / Off Campus Placement?
Companies are looking for Skilled Freshers. So build your technical skills while doing MCA / BTech / BCA / BSc (IT or CS) into below areas- 1. Strong your programming & debugging skills ...

Why we need to learn Programming languages?
Language is medium for communication. If two parties like to communicate or exchange the thoughts they must know a language. Language should be understandable by both the Parties. For example A wants to...

Recommended Articles

Brilliant Academy is one of the reputed institutes for B.Tech tuition classes. This institute is specialised in delivering quality tuition classes for B.E, Engineering - all streams and Engineering diploma courses. Incorporated in 2012, Brillant Academy is a brainchild of Mr Jagadeesh. The main motto of the academy is to...

Read full article >

Lasya Infotech is a Hyderabad based IT training institute founded in 2016 by O Venkat. Believing in his innovation, passion and persistence and with a diverse blend of experience, he started his brainchild to deliver exemplary professional courses to aspiring candidates by honing their skills. Ever since the institute envisions...

Read full article >

Information technology consultancy or Information technology consulting is a specialized field in which one can set their focus on providing advisory services to business firms on finding ways to use innovations in information technology to further their business and meet the objectives of the business. Not only does...

Read full article >

Almost all of us, inside the pocket, bag or on the table have a mobile phone, out of which 90% of us have a smartphone. The technology is advancing rapidly. When it comes to mobile phones, people today want much more than just making phone calls and playing games on the go. People now want instant access to all their business...

Read full article >

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