Cs201 07

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Introduction to Programming Lecture 7 while loop while (condition) { statements; : } statements; While loop executes zero or more times. What if we want the loop to execute at least one time? do­while Do while loop execute on or more times Syntax of do­while loop do { statements ; } while ( condition ) ; Example­Guessing game char c ; int tryNum = 1 ; do { cout << "Please enter your guess by pressing a character key from a to z “ ; cin >> c ; if ( c == 'z‘ ) { cout << "Congratulations! you guessed the right answer“ ; tryNum = 6 ; } else tryNum = tryNum + 1 ; } while ( tryNum <= 5 ) ; Flow chart for do­while loop Do-while Process condition true false Exit Relational Operators char c ; int tryN...
View Full Document

This note was uploaded on 01/12/2010 for the course CS CS 201 taught by Professor Dr.naveedmalik during the Spring '09 term at Virtual University of Pakistan.

Ask a homework question - tutors are online