Do While Loop

In most computer programming languages, a do while loop is a control structure that allows code to be executed repeatedly based on a given Boolean condition. The do while construct consists of a block of code and a condition. The code within the block is first executed, then the condition is evaluated. If the condition is true the code within the block is executed again. This repeats until the condition becomes false. Because do while loops check the condition after the block is executed, the control structure is often also known as a post-test loop. Compare with the while loop, which tests the condition before the code within the block has executed. Note that it is possible, and in some cases desirable, for the condition to always evaluate to true, creating an infinite loop. When such a loop is created intentionally, there is usually another control structure (such as a break statement) that controls termination of the loop. For example, in the C programming language, the code fragment
  x = 0;  do {     x = x + 1;  } while (x < 3); 
first it executes the instruction x = x + 1, then checks the condition x < 3, which it is not, so it executes again. It repeats this execute and check process until the variable x has the desired value, 3.

Demonstrating do while loops

These do while loops will calculate the factorial of a number: In QBasic or Visual Basic:
   Dim Counter as Byte, Factorial as Long   Counter = 5 'Value to take factorial of.   Factorial = 1   Do     Factorial = Factorial * Counter     Counter = Counter - 1   While (Counter > 0)   Print Factorial 'Prints out the result. 
In C or C++:
   int main() {     unsigned int counter = 5;     unsigned long factorial = 1;     do {       factorial *= counter--; /*Multiply, then decrement.*/     } while (counter > 0);     printf("%i", factorial);     return 0;   } 
In Java programming language
   int counter = 5;   int factorial = 1;   do{       factorial *= counter --;   }while(counter > 0);   System.out.println(factorial); 

See also

 

<< PreviousWord BrowserNext >>
harris (porridge)
joseph mcminn
ibm 5250
vishnu sahasranama
mei (company)
revolutionary socialist league (us)
harry grout
revolutionary socialist league
dodge stratus
norman h. bangerter
william carroll
deerhoof
brian wilde
chrysler flathead engine
international socialists (us)
hawksbill turtle
carancho
phillip chen
separable sigma algebra
kendall hailey
stepping stone squeeze
jelly jam
alastair struan
kerbside recycling
list of theme songs which don't mention their show in the lyrics
an thread
woomera, south australia
proxicom
south antrim (constituency)
point loma nazarene university
savannah college of art and design
growing without schooling
chrysler turbine engines
tainted love
jean jacoby
edward gornt
inside out us
erich koch
worker bee
housebreak
samla mammas manna
kucha
hazel wolf high school
thai malay barrier