0
Loops
for(int ii=0; ii<4;ii++){ for(int ii=0;ii<5;ii++){ // } } Can the same variable be used though the scope is different?
3 Respostas
+ 1
If the scope is different than so is the variable
'ii' in the outer loop is a completely different variable from the 'ii' in the inner loop
This is called variable shadowing and happens both in c++ and in python, as well as in many other programming languages
You can't get access to a shadowed variable
+ 1
Yes.
res = 0
for i in [[1],[2],[3]]:
for j in i:
res+=j
+ 1
Yes you can, only in c++ the variable ii will be overridden.