do...while loop in C programming
It often needs to repeat a piece of program as a condition is true (such as the precision of a calculation is insufficient). C offers the following two structures for this:
The do-while statement lets you repeat a statement or compound statement until a specified expression becomes false.
The expression in a do-while statement is evaluated after the body of the loop is executed. Therefore, the body of the loop is always executed at least once.
The expression must have arithmetic or pointer type. Execution proceeds as follows:
The do-while statement can also terminate when a break, goto, or return statement is executed within the statement body.
while (condition) (/ * 1 structure: a condition for entering the code * / repeating instructions; ) do (/ * structure 2: a condition for the release of the code * / repeating instructions; ) While (condition);
Re: do...while loop in C programming
Sometimes we would like to evaluate the condition or at the beginning or the end of the loop, but somewhere in the middle. The trick then is to create an infinite loop (condition always true) and use the break which immediately brought out of the loop:
while (1) (/ * Structure 3: condition in the loop * / Instructions ... if (condition) break; Instructions ... )
|Tags: c programming, loop|
|Thread Tools||Search this Thread|
|Similar Threads for: "do...while loop in C programming"|
|Thread||Thread Starter||Forum||Replies||Last Post|
|Watercooling: Single loop or Dual Loop||Akolekar||Hardware Peripherals||3||21-10-2011 10:52 PM|
|Reboot Loop in Windows 7 Reboot loop and Safe mode doesn't work||mADiRAkSHii||Operating Systems||4||25-01-2011 07:23 PM|
|Socket programming: Is any new Programming Language?||Kushan||Software Development||3||14-11-2009 11:13 AM|
|Help in for loop in C programming||Wyvern||Software Development||3||08-05-2009 10:07 AM|
|JetBrains Introduces a New Programming Paradigm With its Meta Programming System||JoeFrat||Software Development||3||13-12-2008 01:49 PM|