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

Which book is best for learning C programming by a beginner?
C Programming Absolute Beginner's Guide Greg Perry, Dean Miller BeginnersLow-Level Programming: C, Assembly, and Program Execution Igor Zhirkov AdvancedC Programming in easy steps (5th Edition) Mike McGrath Beginners
Anil
0 0
8
What are the flaws of the C programming language?
C programming language does not support Object-oriented programming language
Sounak
0 0
7
Why are there so many programming languages if most programmers use C, C++, Java, and PHP?
This question has the same answer as the question"Why there are so many languages?" has... As they were ask meant for different purpose to serve for different platforms... For short: Link it to the languages used
Veerendra
0 0
7
What is an lvalue?
L-Value stands for left value L-Value of Expressions refer to a memory locations In any assignment statement L-Value of Expression must be a container(i.e. must have ability to hold the data) Variable...
Nagasanthoshi
What is a macro, and how do you use it?
A macro is a fragment of code which has been given a name. Whenever the name is used, it is replaced by the contents of the macro. There are two kinds of macros. They differ mostly in what they look...
Sandeep

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

Ask a Question

Related Lessons

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

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

All About Programming And A Good Programmer.
Hi, This is my first lesson for you guys. Hope you enjoy reading it. In recent community questions, I found many people wanted to be good programmers, or wanted to have good hands on certain language,...

Some interview questions for freshers on C language
Q1. What are the two forms of #include? There are two variants of #include. The one is #include and the other one is #include”file”. In general the first form that is #include is used to...

What is Safety-Critical Software?
A software whose failure may cause death or injuries to the users called Safety-Critical Software.The software present as part of Aeroplanes, or present in Rail as railway signalling software or Automotive...

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