"And" query

Post

Posted
Rating:
#1 (In Topic #143)
Avatar
Guru
cogier is in the usergroup ‘Guru’
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?

Code (gambas)

  1. Public Sub Main()
  2. Dim bTest As Boolean
  3. Dim iValue As Integer[] = [1, 2]
  4.  
  5. If bTest And iValue[2] = 5 Then Print "Hello"
  6.  
Online now: No Back to the top

Post

Posted
Rating:
#2
Avatar
Regular
stevedee is in the usergroup ‘Regular’
 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.
Online now: No Back to the top

Post

Posted
Rating:
#3
Avatar
Regular
jornmo is in the usergroup ‘Regular’
Try And If for short circuiting.

Read more here: /lang/if - Gambas Documentation

Online now: No Back to the top

Post

Posted
Rating:
#4
Avatar
Guru
cogier is in the usergroup ‘Guru’
 Thanks guys, the 'And If' fixed it.
Online now: No Back to the top
1 guest and 0 members have just viewed this.