My co-worker and I discussing about the code readability on simple loops. Suppose a method takes an integer parameter and does some operation on the elements of an array depending on the parameter. e.gFor the sake of simplicity, assume array bounds are negligible and there is no error generated by the codes I presented below.function doSomeOp(targetIndex) {  for(var i = targetIndex + 5; i < someArray.length; i++) {    someArray[i] = 42;  }}as opposed to;function doSomeOp(targetIndex) {  for(var i = targetIndex; i < someArray.length; i++) {    someArray[i + 5] = 42;  }}Is there any advantage to define the loop parameter to simpler values like 0, targetIndex, array.length and then define business logic when using that loop parameter?
Code readability on non-trivial loop variables
readability;loops
For the sake of simplicity, assume array bounds are negligible and there is no error generated by the codes I presented below.So You've introduced an error into your program by forgetting to add the -5 because the second needs it in two places.Also, this is just imho, but the first loop works more like my mind works when interacting with loop (and works more like if you changed it out for an iterator).To the extent the this incredibly marginal issue matters, the first is better.// The second fixed:function doSomeOp(targetIndex) {  for(var i = targetIndex; i < someArray.length - 5; i++) {    someArray[i + 5] = 42;  }}