DEV Community

Discussion on: What The For Loop?

Collapse
 
emilng profile image
Emil Ng

I agree that there's nothing particularly clever about incrementing a counter variable by two in itself. I was just pointing out the risk of going down the clever code path. If I'm maintaining this bit of code that's part of a larger codebase I would want to see something that shows explicit intent like

for(let i=0; i<=20; i++){
  let isOdd = i%2===1
  if(isOdd){
    console.log(i)
  }
} 

There are other replies to the original post that are clearly going down the clever code path so I think it's worth mentioning.