What is the scope of a while and for loop?
while
for
For example, if I declared an object within the loop, what is its behavior and why?
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.