Your quoted input file is unusable/unreadable, since you are not quoting it correctly. Please see Please Read This First: Guidelines and Suggestions for posting LAMMPS questions
Overall, you are misunderstanding how looping and accessing data works. LAMMPS input file scripting is not a full programming language, so the logic that you want to employ cannot work. If you can manually look up individual atom IDs that need to be changed, you can use the set command on them or define a group and then apply set to the group.