Scope of variable declared inside a for loop

后端 未结 5 522
挽巷
挽巷 2020-11-30 15:18
for(int i=0; i<10;i++){
 int j=0;
}

Is j a block variable or a local variable? I see that j\'s scope is only till the for loop ends

5条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-30 15:48

    The word "local" means that something is available somewhere, but not outside the bounds of this "somewhere". In Java variables declared inside a block have a block scope, which means that they're available only inside this block - they're local to it.

提交回复
热议问题