• Post Reply Bookmark Topic Watch Topic
  • New Topic

Scope question [shadowing] (Local scope - block scope)  RSS feed

 
Bora Sabrioglu
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

if we have I thought that the variable 'ouch' declared in the for-loop has block scope and since the parameter is a local variable it has local scope, so 2 different scopes... but it seems to be not like that (since it doesn't compile)...
Someone can explain why the ouch in the for-loop ( a block) is considered in the same scope as the parameter ouch?

thanks!
 
Stephan van Hulst
Saloon Keeper
Posts: 7992
143
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are not allowed to shadow any local variables. Anything declared within a block statement will go out of scope when the block ends, but they are still not allowed to have the same name as any other local variable declared before them.
 
Bora Sabrioglu
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ah, great, thanks....
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!