use for loop than using goto statement

Docker-DCO-1.1-Signed-off-by: Deepak Kumar <deepakkumarnd@gmail.com> (github: 42races)