Is there any way to put to variables in a for loop? Here is an example of kind of what i want:
for (int x,y = 0; int x,y <10; x,y++){
...
}
sure, do this:
1 2 3 4
|
for (int x=0, y=0 ; x < 10 && y < 10 ; x++, y++)
{
// Your code here
}
|
Separating with a comma is required to separate the various parts. Just ensure that you DO split it up completely.
You can also do this:
1 2 3 4 5 6 7
|
for (int x=0; x<10; x++)
{
for (int y=0; y<10; y++)
{
//Stuff here
}
}
|
Last edited on
Yes, the correct syntax is:
for (int x = 0, y = 0; x < 10 && y < 10; x++, y++)
Thanks so much guys! And by the way I do need two identical variables.