Click here to Skip to main content
15,949,686 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
should loop 51 times, writting intergers 0-50 in order.

C#
int i = /*initialiser*/;
while (i/*condition*/50)
{
  i /*iterator*/;

console.writeline(i);
}


What I have tried:

C#
{
            for (int i=0;i<=50;i++)
                for (int j= 1;j<=51;j++)
                {
                    
                    Console.WriteLine(i);
                }
Posted
Updated 19-Nov-18 12:46pm
v2

1 solution

Try
C#
for (int i=0; i< 50; i++)
{
   Console.WriteLine(i);
}
OR
C#
int i = 0;
while i < 51
{
   console.WriteLine(i++);
}

NOTE - in the 2nd example I have incremented i in the first example i is incremented by the use of for
 
Share this answer
 
Comments
Member 13736730 19-Nov-18 19:15pm    
thanks for the reply, going witht the 2nd example it does need an iterator after the while loop to run 51 times doesnt it?
CHill60 20-Nov-18 12:28pm    
Sorry - notifications don't seem to be working and I didn't see this. I'm not sure what you mean by putting "an iterator after the while loop"
i is the iterator in the 2nd example and is incremented by 1 each time (after) it is written to the console by i++
The loop starts at 0 and produces output until i = 50 ... 51 times.

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