Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there another way to take N at a time than a for loop?

Is there a more elegant way to implement going 5 items at a time than a for loop like this?

var q = Campaign_stats.OrderByDescending(c=>c.Leads).Select(c=>c.PID).Take(23);
var count = q.Count();
for (int i = 0; i < (count/5)+1; i++)
{
   q.Skip(i*5).Take(5).Dump();
}
like image 527
Aaron Anodide Avatar asked Oct 11 '12 04:10

Aaron Anodide


People also ask

What can I use instead of loops?

There are other array utility methods like every , slice , splice , some , concat , sort which everyone should be aware of. Using the right kind of function not only makes the code cleaner, but it also makes it easy to test and extend. Plus you are writing futuristic code by using these functions.

How do you iterate n number of times?

The most common way to repeat a specific task or operation N times is by using the for loop in programming. We can iterate the code lines N times using the for loop with the range() function in Python.

Does for loop run'n 1 times?

The loop itself will execute one more time (i.e. when j=n) and see that the value is no longer in range and will not execute the body. So that is why the for-loop executes one more time than the body.

Is map better than for loop?

map() works way faster than for loop.


1 Answers

for(int i = 0; i <= count; i+=5)
{
}
like image 191
idstam Avatar answered Oct 11 '22 14:10

idstam