(val && i) always skips loop if val is 0