Skip to content

Features Variable Scope

Kameron Brooks edited this page Aug 17, 2019 · 1 revision

Variable Scope

CCL supports block scoping

string s = "hello";

{
   string t = s + " world"; // t = "hello world"
}
print(t);                   // t is undefined in current scope

That means for loops, while loops, if statements, else statements, and elseif statements have their own scope. Variables declared inside of a block { } are not available outside of the brackets.

for(int i=0; i < 10; i += 1) {
   print(i);                // i is defined
}
print(i)                    // i is not defined in current scope