"And" query

Post your Gambas programming questions here.
Post Reply
User avatar
cogier
Site Admin
Posts: 1118
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

"And" query

Post 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
User avatar
stevedee
Posts: 518
Joined: Monday 20th March 2017 6:06pm

Re: "And" query

Post 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.
User avatar
jornmo
Site Admin
Posts: 224
Joined: Wednesday 21st September 2016 1:19pm
Location: Norway

Re: "And" query

Post by jornmo »

Try And If for short circuiting.

Read more here: http://gambaswiki.org/wiki/lang/if
User avatar
cogier
Site Admin
Posts: 1118
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: "And" query

Post by cogier »

Thanks guys, the 'And If' fixed it.
Post Reply