UrbanPro

Learn C Language from the Best Tutors

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

Search in

How can you tell if a loop ended prematurely?

Asked by Last Modified  

Follow 1
Answer

Please enter your answer

Professional Tutor with 15 years of experience.

If we check the loop variable we can check whether the loop is terminated or completed.
Comments

Computer Wizard

Generally, loops are dependent on one or more variables. Your program can check those variables outside the loop to ensure that the loop executed properly. For instance, consider the following example: #define REQUESTED_BLOCKS 512 int x; char* cp; /* Attempt (in vain, I must add...) to allocate...
read more
Generally, loops are dependent on one or more variables. Your program can check those variables outside the loop to ensure that the loop executed properly. For instance, consider the following example: #define REQUESTED_BLOCKS 512 int x; char* cp[REQUESTED_BLOCKS]; /* Attempt (in vain, I must add...) to allocate 512 10KB blocks in memory. */ for (x=0; x< REQUESTED_BLOCKS; x++) { cp[x] = (char*) malloc(10000, 1); if (cp[x] == (char*) NULL) break; } /* If x is less than REQUESTED_BLOCKS, the loop has ended prematurely. */ if (x < REQUESTED_BLOCKS) printf(“Bummer! My loop ended prematurely!\n”); Notice that for the loop to execute successfully, it would have had to iterate through 512 times. Immediately following the loop, this condition is tested to see whether the loop ended prematurely. If the variable x is anything less than 512, some error has occurred. read less
Comments

Computer & Maths Professor

Generally, loops are dependent on one or more variables. Your program can check those variables outside the loop to ensure that the loop executed properly. For example, if a loop is executed with the help of i variable 10 times, the value of i if less than 10 (outside the loop) indicates premature end...
read more
Generally, loops are dependent on one or more variables. Your program can check those variables outside the loop to ensure that the loop executed properly. For example, if a loop is executed with the help of i variable 10 times, the value of i if less than 10 (outside the loop) indicates premature end of loop read less
Comments

Tutor

Generally, loops are dependent on one or more variables. Your program can check those variables outside the loop to ensure that the loop executed properly. when the last condition is executed and when the test expression fails the loop will end and the program control goes out from the loop.
Comments

View 2 more Answers

Related Questions

What is the output of the below: int x, y; printf("%d", scanf("%d %d", &x, &Y));
:) Good one. It checks my eye sight. This piece of code would result in an error: "undefined symbol Y". Note: 'scanf( )' not only scans and loads the values entered by users into variables, but it...
Pravalika
How do I become good in competitive programming in a year if I have just started learning C language?
The best topics to learn would be Data structures and also the analysis of algorithms..(THESE ARE BASICS BUT IF U LEARN THEM PROPERLY!!! CODING WOULD BE A PIECE OF CAKE FOR U....)
Anmol
0 0
9
When is a "switch" statement better than multiple "if" statements?
switch statement is generally best to use when you have more than two conditional expressions based on a single variable of numeric type. For instance, rather than the code if (x == 1) printf(“x...
Shalu
In which program we use character constants?
For the name of months, animal, colors we do use it.
Mona

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

Ask a Question

Related Lessons

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...

10 Tips to improve your learning
1. Have a quick revision of topics that you have read in past three days before you start studying a new topic. 2. Make your own notes containing the summary of the topic. 3. Allot proper timing for...

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...


Tress And Its Traversal
Depth First Traversals:(a) Inorder (Left, Root, Right) : 4 2 5 1 3(b) Preorder (Root, Left, Right) : 1 2 4 5 3(c) Postorder (Left, Right, Root) : 4 5 2 3 1 Trees are one of the data structures like...

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 >

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 >

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