use for loop than using goto statement

Signed-off-by: Deepak Kumar <deepakkumarnd@gmail.com>
because you have name = "" already I presume :)