Iteration (Repetition) Constructs Flashcards

(3 cards)

1
Q

How to create a while loop?

A

while (condition)
{
statement block
}
________________________________________________
cout &laquo_space;“\nPlease enter your age : “;
cin&raquo_space; age;
while ( (age <= 0) || (age > 100) )
{
cout &laquo_space;“\nInvalid age.\n”;
cout &laquo_space;“Please Re-enter age : “;
cin&raquo_space; age;
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How to create a do-while loop?

A

do
{
statement block
} while (condition);
______________________________________________________
do
{
cout &laquo_space;“\nEnter Number (0 to terminate): “;
cin&raquo_space; number;
if (number != 0)
{
sum = sum + number;
count++;
}
} while(number != 0);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How to create a for loop?

A

for (initialisation; test condition; re-initialisation)
{
statement block;
}
____________________________________________________________________________
for (count = 0; count <5; count++;)
{
cout &laquo_space;“Hello world”
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly