jeudi 4 mars 2021

Why is this for loop only executed once? [closed]

cin >> input;
for (int i = input - 1; i <= 0; i--)
{
count += 1;
cout << count ;
}

if the input is equal to 3, how many times will this loop be executed? Isn't it be 3 times? (when i = 2, when i = 1, when i = 0) However, when I run this program, it only executed for 1 time. Which part did i write wrongly? is that because when i initialize the variable, i could not put another variable into it? or some other parts that i have written wrongly. I really cannot find out the wrong part. Thank you so much!

Aucun commentaire:

Enregistrer un commentaire