Variable shadowing | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Variable shadowing

If nested loops can have the same variable names but different scopes, is this not a design flaw ? eg) C++, C#. Is there not a language where this is addresed?

9th Jan 2022, 9:15 AM
Sanjay Kamath
Sanjay Kamath - avatar
1 Answer
+ 2
No, it leaves it up to the programmer to make that mistake. If you need to use multiple variables in a nested loop you'd never name them the same. If not, then it's no big deal.
9th Jan 2022, 9:31 AM
Slick
Slick - avatar