Page 1 of 1

"And" query

Posted: Friday 10th November 2017 4:15pm
by cogier
If you look at the code below you will see that the IF statement will fail as bTest is False so why do I get an 'Out of bounds' error from the fact that iValue[2] does not exist. I would have expected that iValue would not be checked as the first part failed. Does this happen in other languages?
Public Sub Main()
Dim bTest As Boolean
Dim iValue As Integer[] = [1, 2]

If bTest And iValue[2] = 5 Then Print "Hello"

End

Re: "And" query

Posted: Friday 10th November 2017 7:19pm
by stevedee
Hi cogier, Gambas is checking your code first and finding an error (that the assignment of the value is illegal or out of bounds). It hasn't got to the stage of evaluating the If expression yet.

Re: "And" query

Posted: Friday 10th November 2017 7:40pm
by jornmo
Try And If for short circuiting.

Read more here: http://gambaswiki.org/wiki/lang/if

Re: "And" query

Posted: Saturday 11th November 2017 12:24pm
by cogier
Thanks guys, the 'And If' fixed it.