richardp

do while control loop - java

Apr 26th, 2014
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.34 KB | None | 0 0
  1. --example #1
  2. set condition value before loop
  3. do{
  4.     // do some work
  5.     // update condition value
  6. }while(condition);
  7.  
  8. -- example #2
  9. int counter = 5;
  10. int factorial = 1;
  11. do {
  12.   factorial *= counter--; /* Multiply, then decrement. */
  13. } while (counter > 0);
  14. System.out.println(factorial);
  15.  
  16.  
  17. http://en.wikipedia.org/wiki/Do_while_loop#Java
Advertisement
Add Comment
Please, Sign In to add comment