C For Dummies, 2nd Edition by Dan Gookin
Author:Dan Gookin [Gookin, Dan]
Language: eng
Format: epub, pdf
Tags: Team DDU
Published: 0101-01-01T00:00:00+00:00
}
while( condition);
23 570684 Ch18.qxd 3/31/04 3:00 PM Page 228
228 Part III: Giving Your Programs the Ability to Run Amok The condition is a true-or-false comparison that while examines â the same type of deal you find in an if comparison. If the condition is true, the statements in the loop are repeated. They keep doing so until the condition is false, and then the program continues. But, no matter what, the statements are always gone through once.
An important thing to remember here is that the while at the end of the loop requires a semicolon. Mess it up and itâs sheer torture later to figure out what went wrong.
One strange aspect of the do-while loop is that it seriously lacks the starting, while-true, and do-this aspects of the traditional while and for loops. It has no starting condition because the loop just dives right into it. Of course, this sentence doesnât mean that the loop would lack those three items. In fact, it may look like this:
starting;
do
{
statement(s);
do_this;
}
while( while_true);
Yikes! Better stick with the basic while loop and bother with this jobbie only when something needs to be done once (or upside down).
ß The condition that while examines is either TRUE or FALSE, according to the laws of C, the same as a comparison made by an if statement.
You can use the same symbols used in an if comparison, and even use the logical doodads (&& or ||) as you see fit.
ß This type of loop is really rare. It has been said that only a mere 5 percent of all loops in C are of the do-while variety.
ß You can still use break to halt a do-while loop. Only by using break, in fact, can you halt the statements in the midst of the loop. Otherwise, as with a while or for loop, all the statements within the curly braces repeat as a single block.
A flaw in the COUNTDWN.C program
Run the COUNTDWN program again. When it asks you to type a number, enter 200.
There isnât a problem with this task; the program counts down from 200 to 0 and blasts off as normal. But, 200 is out of the range the program asks you to type.
23 570684 Ch18.qxd 3/31/04 3:00 PM Page 229
Chapter 18: Do C While You Sleep
229
Use your operating systemâs scroll-back buffer to view the lines that have scrolled off the screen. Hopefully, the DOS prompt or terminal window that youâre using has this feature.
What about typing 0 or a negative number? Try that now; run the program and typeâ5. You see something like this:
T-minus -5
Zero!
Blast off!
The do while loop is executed at least once, so the -5 is displayed. Ack! It isnât one of the great boo-boos of modern programming history, but itâs bound to startle the astronauts, who are expecting a leisurely though suspenseful takeoff sequence.
The way to guard against this faux pas is to write a special loop to ensure that the value that is typed is kosher. Yes, itâs a kosher number loop. That is handled quite brilliantly by do-while.
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Personalized inhaled bacteriophage therapy for treatment of multidrug-resistant Pseudomonas aeruginosa in cystic fibrosis by unknow(174836)
CONSORT 2025 statement: updated guideline for reporting randomized trials by unknow(83237)
Critical evaluation of the ProfiLER-02 study design and outcomes by Vivek Subbiah & Razelle Kurzrock(82906)
Cardiac gene therapy makes a comeback by Oliver J. Müller & Susanne Hille & Anca Kliesow Remes(82754)
Whisky: Malt Whiskies of Scotland (Collins Little Books) by dominic roskrow(74436)
Unveiling the design rules for tunable emission in graphene quantum dots: A high-throughput TDDFT and machine learning perspective by Şener Özönder & Mustafa Coşkun Özdemir & Caner Ünlü(50890)
A yeast-based oral therapeutic delivers immune checkpoint inhibitors to reduce intestinal tumor burden by unknow(40259)
Covalent hitchhikers guide proteins to the nucleus by Alexander F. Russell & Madeline F. Currie & Champak Chatterjee(40215)
Meet the Authors: Christopher R. Mansfield and Emily R. Derbyshire by Christopher R. Mansfield & Emily R. Derbyshire(40094)
Alkaline-earth metals promote propane dehydrogenation with carbon dioxide through geometric effects: Altering the reaction pathway by unknow(32730)
Induced iron vacancies boosting FeOOH loaded on sustainable Fenton-like collagen fiber membrane for efficient removal of emerging contaminants by unknow(32504)
Efficient electric-field-assisted photochemical conversion of methane to n-propanol exclusively over penetrated TiO2Ti hollow fibers by Guanghui Feng(32452)
Bi2SiO5 nanosheets as piezo-photocatalyst for efficient degradation of 2,4-Dichlorophenol by Hangyu Shi & Yifu Li & Lishan Zhang & Guoguan Liu & Qian Zhang & Xuan Ru & Shan Zhong(32384)
A novel NDIPTA organic heterojunction photocatalyst with built-in electric field for efficient hydrogen production by Jiahui Yang & Baojun Ma & Yongfa Zhu(32360)
Enhanced conversion of methane to liquid-phase oxygenates via hollow ferrite nanotube@horseradish peroxidase based photoenzymatic catalysis by Jun Duan & Shiying Fan & Xinyong Li & Shaomin Liu(32330)
Ordered macroporous superstructure of defective carbon adorned with tiny cobalt sulfide for selective electrocatalytic hydrogenation of cinnamaldehyde by Xiao-Shi Yuan & Sheng-Hua Zhou & San-Mei Wang & Wenbo Wei & Xiaofang Li & Xin-Tao Wu & Qi-Long Zhu(32256)
What's Done in Darkness by Kayla Perrin(27144)
Topological analysis of non-conjugated ethylene oxide cored dendrimers decorated with tetraphenylethylene: Insights from degree-based descriptors using the polynomial approach by A Theertha Nair & D Antony Xavier & Annmaria Baby & S Akhila(26522)
Investigation of mechanical and self-healing properties of hydroxyl-terminated polybutadiene functionalized with 2-ureido-4-pyrimidinone by Mohsen Kazazi & Mehran Hayaty & Ali Mousaviazar(26457)