I would work out a away to know for fact what you have so you can eliminate the loops/nested branches on weapon switch. You should only really need to loop, if at all, when you add or remove a weapon.
More details on your setup would help us figure out an optimal approach. A walk through on the weapon setup and thought process on the weapon switching logic you’ve implemented.
edit … Is this for a Weapon Mastery type game mode? Weapon switch on progression type thing?