answersLogoWhite

0


Best Answer

There are rare occasions where you would do that, but in general you don't want to do that for most while loops because the semi-colon is a statement by itself (it becomes part of the loop).

For example,

while (a > b) ;

would terminate the loop body, whereas:

while (a > b) b++ ;

would have the increment of 'b' as part of the loop.

In the first example it might cause an infinite loop, depending on whether or not a is greater than b.

The semi-colon character means the semantic end of a statement. Putting it with the while logically doesn't make much sense most of the time.

Note: Never say never, for example the following is completely legal:

while ((*to++ = *from++)!='\0');

User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Why should you never put a semicolon at the end of the while loop's parentheses?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

How do you use printf without semicolon in c?

Example:printf ("There is one semicolon; in this string");printf ("There is no semicolon in this string");


Why it is necessary to avoid infinite loop in program design?

It is not necessary to avoid infinite loops. You are perhaps confusing infinite loops with endless loops which are to be avoided at all costs. An endless loop is an infinite loop that has no reachable exit condition; the loop will iterate until we forcibly terminate the program. We use the the term infinite loop in the sense that it is impossible to measure or calculate when the exit point will be hit. the following are all examples of infinite loops in their simplest form: for (;;) { // ... } while (true) { // ... } do while (true) { // ... } endless: // ... goto endless; The conditional expressions in each of these loops can never be false thus we cannot easily determine when these loops will exit. We typically use infinite loops when there are many exit conditions to consider and it is either impractical or inefficient to evaluate all of those conditions via the controlling expression alone. We take it as read the exit conditions are contained within the body of the loop. If the body of the loop has no reachable exit condition then it becomes an endless loop. It is the programmer's responsibility to ensure that all infinite loops can exit at some point.


What do you know about for loop and do while loop?

The condition for a while loop is tested at the start of the loop. It is tested at the end of the loop for a do-while loop. The body of a do-while loop will always be executed at least once. Whereas for a while loop if the condition is false to start with, the body of the loop is never executed.


Should you wear gloves around powered rotating equipment?

no you should never wear them


Why did the world of the future never arrive?

How should i know

Related questions

When do you use a semicolon in algebra?

Well, according to what I learned when I was in Algebra I, you should never have to use a semicolon.


How do you dial a semicolon on a landline phone?

You can't dial a semicolon on a landline phone, nor on a mobile phone, for that matter. It's probably a good thing, then, that you never need to dial a semicolon on any kind of telephone, since a semicolon cannot be part of a telephone number.


Why is the x and y axis always in parentheses?

40 years as a mathematician and I have never seen them in parentheses!


Where should the semicolon be placed Yesterday the professor said I will collect your papers tomorrow however he never did collect the?

The semicolon should be placed after "tomorrow," like this: "Yesterday the professor said, 'I will collect your papers tomorrow'; however, he never did collect them."


How do you write a semicolon with two independent clauses?

The semicolon separates the two clauses, just as the word "and" would, in the same sentence. Be careful to never capitalize the first letter of the second clause, unless it is a name, title, etc.


How do you use printf without semicolon in c?

Example:printf ("There is one semicolon; in this string");printf ("There is no semicolon in this string");


How to properly use the semicolon in a sentence?

Use a semicolon to separate two independent clauses that are closely related and could stand alone as separate sentences. It can also be used to separate items in a list when the items themselves contain commas. Make sure not to overuse semicolons; they should be used sparingly for clarity and emphasis.


What is a semicolin?

A semicolon is a punctuation mark (;) that can be used to connect two ideas. For example: Sheila is a very smart girl; she never gets less than an A.


Why not to use nested for loops 3 times?

You never want to use nested loops if you can avoid it. Each additional level of loop you add increases the work done by your program exponentially. There are certain cases where this is unavoidable, of course. For example, iterating over objects in 2D or 3D space can require many levels of nested loops.


How many spaces after a colon and semicolon?

After a semicolon, there is never more than one space. Spacing after colons (and periods) depends on the style guidelines you're using. Some call for one space, others for two. The most important thing, however, is to be consistent. Use the same spacing after colons as you do after periods throughout the entire document.


How do you properly us a semicolon?

A semicolon joins two independent clauses (an independent clause is basically something that could stand alone as a sentence) that are linked in subject in some way. So... Joe was sad; his dog died. That is a correct way to use a semicolon, although Joe was sad. His dog died. and Joe was sad that his dog had died. are also just as correct. However, Joe was sad; Eleanor was excited to be moving to Israel. would only be correct if Eleanor's impending travel is the reason for Joe's sadness. If they are relatively unrelated people and you are just discussing their different emotions, then making them two separate sentences is less confusing. Remember... you should never use a semicolon in place of a comma or other punctuation. You can only use it in the place of a period, and then only if the sentences are very closely related. ; You will find the answer to your question in the Related Link below.


How is Fruit Loops made?

with love and pain and suffering. They are forged in the factory of fire and brimstone. they must never see the light of day. Love is their food.