jeudi 25 avril 2019

Netlogo Variable Scope with Let

General CS question because I was surprised by behavior of let in Netlogo.

If I declare a variable from within an if statement per below, is it common for the scope of that variable to be limited to that if statement?

I thought scope generally referred to functions rather than constructs like a loop or if statement. How common is that?

if x > y :
     int i = 2
else:
     int i = 3

print(i)

would return: "error: (i) does not exist" 

Aucun commentaire:

Enregistrer un commentaire