"And" query

Post Reply
User avatar
cogier
Site Admin
Posts: 115
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

"And" query

Post by cogier » Friday 10th November 2017 4:15pm

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

stevedee
Posts: 42
Joined: Monday 20th March 2017 6:06pm

Re: "And" query

Post by stevedee » Friday 10th November 2017 7:19pm

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: 127
Joined: Wednesday 21st September 2016 1:19pm
Location: Norway

Re: "And" query

Post by jornmo » Friday 10th November 2017 7:40pm

Try And If for short circuiting.

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

User avatar
cogier
Site Admin
Posts: 115
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: "And" query

Post by cogier » Saturday 11th November 2017 12:24pm

Thanks guys, the 'And If' fixed it.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest