0

Why 10 is counted and why 0 is not in the output

static void Main(string[] args) { for (int x = 10; x > 0; x-=2) { Console.WriteLine(x);

24th Feb 2020, 5:04 PM
Erfan Mostafavi
Erfan Mostafavi - avatar
4 Réponses
+ 6
If you use only the sign of 'greater than' the number zero is not contemplated and therefore not shown in the for cycle
24th Feb 2020, 5:08 PM
Cmurio
Cmurio - avatar
+ 5
Is x >=0 To show you 0 not x >0
24th Feb 2020, 5:07 PM
Cmurio
Cmurio - avatar
+ 2
0 is not counted because 0 is not greater than 0 in the for loop condition. if you want 0 to be counted you’d change the condition to x >= 0;
24th Feb 2020, 5:08 PM
Kylie
Kylie - avatar
+ 1
Thanks everyone 💙
24th Feb 2020, 5:14 PM
Erfan Mostafavi
Erfan Mostafavi - avatar