The note about "variable may be unused" is a warning, not an error. I'm not sure how this applies to your code example and description, as 'n' is a constant and 'a' is undefined. Both n and a appear to be used by tests, though I'm assuming that this is only the interior of a loop, so I really can't know what's missing.
The 'may be unused' warning usually pops up when a value is assigned to a variable and then it is immediately overwritten before the new value is used. If the loop indeed starts with n being assigned a constant value, then its reassignment within the conditional structure is of no consequence. Any changes to n will be overwritten as soon as the next cycle starts. Perhaps the initialization of n=1; is supposed to be outside of the loop?
If it's a warning, it shouldn't prevent the code from running. If your code is doing what you want and the warning is something you find bothersome, you can disable it in preferences. Under Preferences>MATLAB>CodeAnalyzer, search for the error string and disable the relevant one.