Not sure if I am asking correctly, but I have something like the following:
def x = 1
if (x == 1) {
def answer = "yes"
}
println answer
I get the error - No such property: answer for class...
However, this works:
def x = 1
def answer = ''
if (x==1) {
answer = "yes"
}
println answer
Is this because variables have a local scope when they are inside of an If statement? Is there a better way to code this or do I just need to declare all my variables outside of the If statement first?