edited code: for loops