What is the scope of a 'while' and 'for' loop?

后端 未结 10 1664
有刺的猬
有刺的猬 2020-11-30 06:37

What is the scope of a while and for loop?

For example, if I declared an object within the loop, what is its behavior and why?

10条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-30 07:03

    The variable is within the scope of the loop. I.e. you need to be within the loop to access it. It's the same as if you declared a variable within a function, only things in the function have access to it.

提交回复
热议问题