So what is the difference between the following codes in a standard for loop:
list.get(i) //I know this holds the current element in the list.
list.get(i+1);
list.get(i -1)
list.get(i) + 1) //I think this one grabs the next element following the current element????
list.get(i) -1)
I am a little confused as to how this works...or how to implement it.
Thanks.
So what is the difference between the following codes in a standard for loop?
Under discussion
Comments (4)
- Popular
- New
- Old
You must be signed in to leave a comment
Nouser
8 February 2021, 10:03useful
+1
MCantu
8 February 2021, 19:19
Thank you so much, it makes more sense now that you explained it. So just to make sure I got it...
(list.get(i) + 1); this adds 1 to the value of i. (example if i= 4 ) return will be 5.
list.get((i) + 1); this code gets the next element from current one.
(example: 4 5 6 8 9) if current element is at 6, the previous code will return 8. right?
0
Nouser
9 February 2021, 08:58
(list.get(i) + 1); this adds 1 to the value of i. (example if i= 4 ) return will be 5.
I'd say it get's the value at index i in the list and adds 1 to that value.
Why not have a live example. That makes everything much clearer ;)
0
MCantu
9 February 2021, 16:39
Sweet! Live examples are awesome and always welcome. thank you for your time. :)
0