do-while


The last type of loop is the post-test, or do-while, loop. This loop will execute its contents at least once; then the conditional is tested and, if true, the loop will continue until the condition is false.

For example, if we have the same problem as previously presented, but we are guaranteed to always have at least one item in the cart, we might do the following:

 <cfscript>      //Set the number of the item to display      index = 1;      //while loop      do{          //Output the item at the specified index          WriteOutput(shopping_cart[index]);          //Increment index          index = index + 1;      }while(index LTE cart_size)  </cfscript> 

This will do the same thing as the regular while loop, but it will always display at least one item.



Inside ColdFusion MX
Inside Coldfusion MX
ISBN: 0735713049
EAN: 2147483647
Year: 2005
Pages: 579

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net