Answer the question
In order to leave comments, you need to log in
What is the best way here?
Let's say there is a function area. This function is called once per second by a constant timer.
We need to "comb" a lot of arrays in this function. Here is the question: to use one common loop of the form:
for(var i = 0; i < MAX_LENGTH_OF_ARRAYS; i++)
{
if(i < LENGTH_FIRST_ARRAY) // если i в области существования ячеек первого массива
{
// действие с массивом 1
}
else if(i < LENGTH_SECOND_ARRAY) // если i в области существования ячеек второго массива
{
// действие с массивом 2
}
// и так со всеми массивами
}
Answer the question
In order to leave comments, you need to log in
Well, given that the above option is not working at all and only the first array will be processed completely, it is better to have your own loop for each array.
In general, the overhead for a loop is not large, so each loop on its own array is not so scary.
And given that the code with one cycle is more difficult and worse to read, and even so much so that you have already made mistakes, it is better to have your own cycle for each array.
See how many arguments there are for this option - choose it.
How are arrays passed? So far, the winning option is - each array has its own cycle. What language?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question