creating for loop in error()