The problem with this script is that after the loop has finished (ie looped 5 times), _gun = "UZI".
The script then continues past ?_i <_c : goto "start" and goes onto the #yes section. So Even if the unit has no gun, the script will always return hint "The player has a UZI" at the end.
You need to exit the script after the last loop like so:
_unit = _this select 0
_handguns = ["Glock","Revolver","Beretta","Skorpion","UZI"]
_c = count _handguns
_i = 0
#start
_gun = _handguns select _i
?_unit hasweapon _gun : goto "yes"
_i = _i + 1
?_i <_c : goto "start"
exit
#yes
hint format ["The player has a %1",_gun]
exit
Btw, the "UZI" is not a handgun - that is the primary weapon slot version. The handgun Uzi is "Ingram".