For (int i = 0; i < array.length - 1; i++)

>for (int i = 0; i < array.length - 1; i++)

Attached: 1535196219968.png (588x823, 105K)

C masterrace

yeah it's i < array.length

You should store the length somewhere if it's not going to chance because otherwise it will query it many times and I know compilers will optimize it out if they know it's not going to change but I'm autistic and want to be sure

>for (int i = 0; i < array.length - 1; i++) f(i,i+1);
Just shift it by one:
>for (int i = 1; i < array.length; i++) f(i-1,i);

for (let x of array)
master race

> - 1
why tho

That particular example is for iterating through an array in Java, if an array has 6 elements, the indices will be 0 - 5, so you want to start at index 0 and end at 5.

Except it wouldn't end at 5, it would at 4 in OP's loop. It'd end at 5 if it was i

It seems I fell into OP's trap.
I should really try reading things properly more often.

who actually does this?
but arrays start at 0

Attached: ManrayfaceH.jpg (300x289, 15K)

>i < array.length - 1
are you retarded or is this part of your joke?

Actually x should be a const, since the loop is creating a new instance for each iteration anyway.

if you're using any modern compiler that has for loops, it will get optimized out

How would you do it?

What the fuck is wrong with you retard?

>for item in list:

Attached: hammerhead.jpg (585x399, 79K)

not him, but array starts at 0, which means if it the length is 5, with OP code you'll stop after 3 because it's a strict < and not

you are like little babies
watch this

for (int i -> array.length)
as i approaches the length of array

Attached: 1440677953971.jpg (890x890, 116K)

>calling array.length every iteration

Attached: Brainlet_f3217f_6615771.png (1200x1335, 269K)

array.length is going to have the exact same performance as copying it to a local variable in every language that matters. it's stored at an address immediately before the array elements.

>>for (var i = 0, l = array.length; i < l; i++)

fixed /emote smiley

>it's stored at an address immediately before the array elements
Very few list implementations work like that.

What the hell are you talking about? That's how arrays in most languages work. The length must be stored somewhere because there's no other way to know it for an array.

for(MyObject myobject: MyObjectList) {}

for (i = array.length - 1; i--; )

C++ master race here
for (register violate int i = 0; i < len; ++i)

FUCK volatile**, excuse my misspelling.

>not std::for_each
shiggy

(loop for i across arr)

Attached: 834.png (680x760, 191K)

It's stored "somewhere" but not usually "immediately before the array elements" like you said.
Usually a list is implemented as a struct containing the current length, capacity, and a pointer to the memory address that the elements start at. The elements are not usually stored contiguously with the list metadata.

#define DO(z,n,f) do{typeof(z) i, _n=(n);for(i=z; i

>i=0;
>while(1)
>{
>i++;
>if(i==array.length) break;
>}