In R, why does the j
variable defined in the below for-loop remain in the global environment/scope after the loop execution.
for (j in 1:2){
print(j)
}
Screenshot of terminal window with code execution where you see the variables in the global environment before and after the for loop execution.
It is a design choice. If you look at the documentation
It says
I expect that is so that if you jump out of the loop, say with
last()
you can know which index you were on.