I’m making a grid of Row=5 and Col = 8. Using this gird to instantiate. So actually 40 GameObjects are being Instantiated. But I want to to print 0 to 40 in a separate for loop. I have created the for loop in Start()
I’m not supposed to use any variables, add, subtract, multiply or divide do anything thin but just by using i and j. Getting me? Not to use Row and Col variables too in the statement.
Row = 5, Col = 8;
for(int i=0;i<Row;i++)
{
for(int j=0;j<Col;j++)
{
//Print 0 to 40, just by using i and j, don't use any variables.
}
}
1 Answer
1
As it was pointed out in the comment, your question is lacking the question. I assume your comment reply is your actual question?
I’m making a grid of Row=5 and Col = 8. Using this gird to instantiate. So actually 40 GameObjects are being Instantiated. But I want to to print 0 to 40 in a separate for loop. I have created the for loop in Start().
First of all, please format code as code. The editor on this site has a button for preformatted code </> button. Just insert the code between the 3 backticks
```
your code goes here
```
So it would look like this:
Row = 5, Col = 8;
for(int i=0;i<Row;i++)
{
for(int j=0;j<Col;j++)
{
//Print 0 to 40, just by using i and j, don’t use any variables.
}
}
You can also write “CSharp” after the 3 opening backticks to get proper C# syntax highlighting:
Row = 5, Col = 8;
for(int i=0;i<Row;i++)
{
for(int j=0;j<Col;j++)
{
//Print 0 to 40, just by using i and j, don’t use any variables.
}
}
SOLUTION
Anyways, in order to print the numbers 0 to 39 you would just do (i*Col + j)
Debug.Log(""+i+" * "+Col+" + "+j+" == " + (i*Col + j));
So for every completed row you have to add one full length of that row (so Col).
ps: I just read that you want to print the number in a separate loop? That sounds kinda weird, especially since you said no extra variable. That second loop would require it’s own loop variable in order to be able to loop and have a breaking condition. So I’m confused what you actually want. Is this an assignment? We’re not here to help with homework ^^. This is about game development.
What is the question?
– edpereirajrI'm making a grid of Row=5 and Col = 8. Using this gird to instantiate. So actually 40 GameObjects are being Instantiated. But I want to to print 0 to 40 in a separate for loop. I have created the for loop in Start().
– GauravRathod11I'm not supposed to use any variables, add, subtract, multiply or divide do anything thin but just by using i and j. Getting me? Not to use Row and Col variables too in the statement.
– GauravRathod110 to 40 are 41 numbers.
– edpereirajrsorry 0 to 39 numbers.
– GauravRathod11