ReSharper
 
Get ReSharper
Get your hands on the new features ahead of the release by joining the Early Access Program for ReSharper 2025.1! Learn more

Code inspection: Empty 'for' loop is redundant

Last modified: 11 February 2024

If a for loop contains no instructions, and its initialization, condition, and iteration do not use variables from the outer scope, ReSharper suggests removing this loop, for example:

Note, however, that a for loop with an empty body could be actually used to iterate through external variables, in which case ReSharper will not highlight it as redundant, for example: