how to make if behave differently



if xxx() AND yyy() then...

Is there any alternative if that does not evaluate the yyy if xxx is false?
kamleshmistryAsked:
Who is Participating?
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
If xxx() AndAlso yyy() Then

End If

If xxx() OrElse yyy() Then

End If
0
 
ClifCommented:
Simple...

If xxx() Then
    If yyy()
        'Only if xxx() and yyy() are true
    End If
End If
0
 
ClifCommented:
Ok, let's try the proper syntax...

If xxx() Then
    If yyy() Then
        'Only if xxx() and yyy() are true
    End If
End If
0
 
ptakjaCommented:
AndAlso and OrElse are new keywords in VB.Net that short circuit compound conditionals if a preceding expression evaluates to false.  These can be combined to more than 2 expressions as:

If xxx() AndAlso yyy() AndAlso zzz() Then

End If

In this case the only way zzz get evaluated is if xxx and yyy are both true.

Jeff
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.