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

How do I learn C programming by videos or books?
BOOKS AND PRACTICE by far remain the best way for learning any language ....
Fgrefg
0 0
5
What is the error in the given C language program?
There are three types of errors exist in C Programming: Syntax errors, Semantic errors and runtime errors.
Suresh
0 0
5

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

Ask a Question

Related Lessons

PRACTISE makes you PERFECT ; ; ; There is no SUBSTITUTE for HARD WORK ;;;;Breathe SUCCESS like OXYGEN
Proper Planning ( reg what portions to be covered today) revising today's class portions & clarifying doubts solving Maths problems regularly ,noting down formulae separately trying to understand...

C++ Program-Working with constant using #define preprocessor
//Header Files #include#include // using #define preprocessor for defining a constant#define len 10#define br 5#define rad 3#define NEWLINE '\n' //Main function void main(){ int area_r; float area_c; //Function...

Tips of learning Java Language/Other Programming Languages
1.You should know the basic concept: If we talk about programming languages so basic concept are same in all the high level languages. So you should know the basic concept firstly then you can easily understand...
I

ICreative Solution

0 0
0

Dynamic Memory Allocation in C using malloc()
#include <stdio.h>#include <conio.h>//#include <malloc.h> OR#include <stdlib.h>void main(){ int *ptr, i, n, sum = 0; printf("how many elements ? "); scanf("%d", &n);...

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