1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
#include <iostream>
#include <windows.h>
using namespace std;
int main()
{
int a=10;
while(a>=0)//10,9,8,7,6,5,4,3,2,1,0
{
cout<<a<<",";
a--;
Sleep(300);
}
a=1;
//bring a=1 from while loop to outside where it does not repeat, solves the problem
//start from a=1, if not, two zeros will come out
while(a<=10)
//1,2,3,4,5,6,7,8,9,10
//if you were to use while(a=1,a<=10), every time while loop repeats, a=1, creating infinite loop
{
cout<<a<<",";
a++;
Sleep(300);
}
}
|