COP 3223C Lecture Notes - Lecture 15: Scanf Format String
Document Summary
In our while loop we saw that the minimum # of times that the loop code is run is 0. There are times when you might want to have the code run at least 1 time. For example when requesting data that has to be validated. In such a case we have the choice of using a different kind of loop - the do while loop. Note: there is a ; at the end of the expression do{ statement1; statementn; Example: do{ ask customer to select a drink read drink selected check if selection is valid. Example int choice; do{ printf( select a drink from 1-15\n ); scanf( %d , &choice); Note that although the expression evaluates to false, the do while loop will be executed at least 1 time. So this type of loop is called a post-test loop (the condition is only tested after the statement/s of the loop have been run)