can vectorize this for-loop with update variable in each iterate

join shbcf.ru