Professional Documents
Culture Documents
Fall 2017
Engr. Muhammad Raees
raees.se@must.edu.pk
while(bool-expression)
{
//repeatedly executed as long as the expression is true.
}
int nYear = 1;
while (nYear < 10)
{
// . . . whatever . . .
}
int year = 1;
do
{
// . . . some calculation . . .
year = year + 1;
} while (year < duration);
Department of Software Engineering, MUST. Mirpur AJ&K 10
▪ In contrast to the while loop, the do . . . while loop is executed at
least once, regardless of the value of duration.
int num = 1;
while(num < largerNum)
{
int average = value / num;
// . . . some series of commands . . .
num++;
}
▪ How can you determine how fast your own computer really
operates? Write a program with a while loop that counts from 1 to
300,000,000 by 1s. Every time the count reaches a multiple of
100,000,000, print that number on the screen. Use your watch to
time how long each 100 million repetitions of the loop takes.