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

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

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

View 1 more Answers

Related Questions

What is the best IDE for C and C++ development?
If you're a student then Turbo C++ is best for C and C++ program + inbuilt C/C++ Graphics Function If you're a professional or working then Netbeans for C/C++ or Code:: Blocks is Best.
Balakrishnasingh
Why is the C language important?
C language is a high-level, general-purpose programming language. It provides a straightforward, consistent, powerful interface for programming systems. That's why the C language is widely used for developing...
Ganesh
0 0
5
What is the actual size of INT in the C language, 2 or 4 bytes?
The actual size to int is determined by the compiler as the program runs. But theoretically the size is 2 bytes. You can increase the size by adding keyword long infront of it to make the size 4 bytes. Eg int a; // 2 bytes Long int b; // 4 bytes
Kunal
What is = and == in C language?
= is assignment operator while ==is comparision operator
Sayed
0 0
7
how much time does it take to learn c language from basic to advance range
3 month and also depend in your skill to learning power...
Nithin

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

Ask a Question

Related Lessons

Static and dynamic libraries
A library is a package of code that is meant to be reused by many programs. A static library (also known as an archive) consists of routines that are compiled and linked directly into your program. When...

Array vs Linked List
Array Linked List Accessing element is easy. Accessing element is difficult compare to Array. Easy to use. Difficult to use. Memory is Fixed size. Memory is variable size. If...

Difference Between C Language and C Program
C Language: C Language is structured, high level and machine independent language. C Program: C Program is the collection of functions that are supported by C library.
S

Shashwat Kumar

0 0
0

Structures in C
A structure is a collection of one or more data members possibly of different data types, grouped together under a single name for convenient handling. Defining a Structure: In general terms,...

Recommended Articles

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 >

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 >

Business Process outsourcing (BPO) services can be considered as a kind of outsourcing which involves subletting of specific functions associated with any business to a third party service provider. BPO is usually administered as a cost-saving procedure for functions which an organization needs but does not rely upon to...

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 >

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