java - Why does this array give me trouble? -


this question has answer here:

if write this:

int array[] = {2, 2, 4, 6, 8, 5}; (int : array) {  } 

..it's ok, if write this:

int array[] = {2, 2, 4, 6, 8, 5}; int = 0; (i : array) {  } 

it gives me issues. teacher says wants initialize @ top, how doesn't put int inside of for...

is there other ways write it?

the syntax you're using special case of loop, called "for-in" loop. teacher wants more traditional c style loop this:

for (int = 0; < array.length; i++) {     // need array[i] access elements here } 

the difference for-in loop doesn't use counter (loop induction variable), uses uninitialised value i , binds name each element of array iterate.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -