You are declareign x twice, once here:
int x = 1;
And once here:
for(int x = 1;i<=10;i++)
That's not a good idea as the compiler will tell you:
A local variable named 'x' cannot be declared in this scope because it would give a different meaning to 'x', which is already used in a 'parent or current' scope to denote something else
And you don't declare
i
at all!
Then there is the ending condition, which isn't the same for the two loops - your new one would perform an extra iteration because it continues to run even when
i
is equal to 10.
To change this
int x = 1;
while (x < 10)
{
Console.Write(x);
x++;
}
to a
for
loop, just do this:
for (int x = 1; x < 10; x++)
{
Console.Write(x);
}