for (x = 0; x < 10; x++)
{
for (y = 0; y < 10; y++)
{
print ("Y: " + y);
print ("X: " + x);
}
}
So just some quick background, I have been trying to learn Unity Java for a few days now and seem to be a little confused regarding the above snippet of code.
As far as I am aware it will go through the first for() once and execute whatever code is inside it and when it gets to the second for() nested within it will go through that first until it is finished and then go back to the first for once it does with the nested for()
Now could someone explain to me why; if i am telling it to print (x) in the second for() why do the numbers print exactly the same as if I had the print (x) in the first for.
eg
y: 0
x: 0
y: 1
y: 2
y: 3
y: 4
y: 5
y: 6
y: 7
y: 8
y: 9
x: 1
x: 2
x: 3
x: 4
x: 5
x: 6
x: 7
x: 8
x: 9
I would have thought if i put the print x in the nested for() it would print:
x: 0
y: 0
x: 0
y: 1
x: 0
y: 2
x: 0
x: 3
etc… untill it goes back to the first for() wouldnt x stay as 0?
Sorry if I have confused you with the lack of terminology or bad explanation I am doing my best.