Академический Документы
Профессиональный Документы
Культура Документы
|
Outline
• while loop
• do… while loop
• for loop
• What is a loop?
• Loops have a purpose to repeat a statement a certain
number of times or while a condition is fulfilled.
int main()
{
int count;
count=1;//why do we need to initialize?
while(count<=10)
{
cout<<count<<" ";
count=count+1;/*the new value of count is incremented. What is the
shorthand code for this?*/
}
system("pause");
return 0;
}
• Syntax
do
{
}while (condition);
Write the
equivalent of this
program using a
for loop.