use for loop than using goto statement

Signed-off-by: Deepak Kumar <deepakkumarnd@gmail.com>