Click here to Skip to main content
15,885,141 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
for (int i = 20; i > 0; i=i - 2)
{
Console.WriteLine(i)
}
Console.ReadLine();

What I have tried:

I'm having trouble understanding as I'm new to C#
Posted
Updated 16-Nov-18 4:31am
Comments
Keith Barrow 16-Nov-18 6:08am    
Why can't you run code. This is obviously an exercise question - but it seems odd that you wouldn't run the code.

This will print all even numbers starting at 20 descending
20
18
16
14
12
10
8
6
4
2
Please use this online compiler to exercise C# syntax,
C# Online Compiler | .NET Fiddle[^]
Good luck,
 
Share this answer
 
v2
Comments
Dave Kreskowiak 16-Nov-18 14:24pm    
That's nice and all, but next time, don't do the OP's homework for them. It really doesn't help them think about the problem.
Nothing would be printed.
Your code wouldn't even compile.
C#
for (int i=20; i>0; i = i-2)
{
   Console.WriteLine(i)
}

A semicolon is missing at the end of line 3.
If you corrected this error like this:
C#
for (int i=20; i>0; i = i-2)
{
   Console.WriteLine(i);
}

then you would get the result as described in solution 1.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900