DEV Community

Discussion on: Getting Started with Go - Variables

Collapse
 
johannesvollmer profile image
Johannes Vollmer

Nice!

This program would panic immediately after the first print statement. it will throw error no new variables on left side of :=

Is that a runtime error?

Collapse
 
j3rn profile image
Jonathan Arnett

I experimented with it and it appears to be a compile-time error. I've tried a handful of different ways to make a variable's declaration non-deterministic in my code, and I haven't found a way yet (though that's no proof that it isn't possible). For instance, it appears that if you declare a variable in a if block, that variable goes out-of-scope at the end of the block.