Difference in coding style

java

Solution

Is there any significant difference between following code:

Just the difference of scope of `int s`. In former, it would not be visible outside the for loop. Whereas, it would be in the later case. As far as best practices is concerned, you should try to minimize the scope of local variables as far as possible. So, if you are not using `int s` outside the `for` loop, then it's better to declare it inside only.

Problem

Is there any significant difference between following code: ``` for(int i=0;i<100;i++){ int s =i; } ``` and ``` int s=0; for(int i=0;i<100;i++){ s =i; } ```

Original source

Related problems