Why does the following work fine?
String str; while (condition) { str = calculateStr(); ..... }
But this one is said to be dangerou
Variables should be declared as close to where they are used as possible.
It makes RAII (Resource Acquisition Is Initialization) easier.
It keeps the scope of the variable tight. This lets the optimizer work better.