ReSharper 2024.1 Help

Code Inspection: Empty control statement body

Category

Common Practices and Code Improvements

ID

EmptyEmbeddedStatement

EditorConfig

resharper_empty_embedded_statement_highlighting

Default severity

Warning

Language

C#

Requires SWA

No

There are cases where you need to have control statements (statements that normally require a body, for example while or foreach) with an empty body. One example is a busy loop where a while statement does nothing in its body.

If you use an empty statement as a body, for example while (DoSomething()) ;, ReSharper suggests replacing the empty statement with an empty block, that is while (DoSomething()) {}.

With the empty block, you are less likely to come across issues like the following when you later modify your code:

while (DoSomething()) ; // while loop actually ends here with the empty statement { DoSomethingElse(); }
Last modified: 15 April 2024