It is good style to limit the scope of variables as much as possible. Sometimes, however, one first needs to obtain some value, and only if it fits a certain condition, it can be processed further.
For this purpose, C++17 comes with if and switch statements with initializers.