WoWInterface - View Single Post - Help with if and 'and not'
View Single Post
10-29-16, 04:27 AM   #8
A Theradrim Guardian
AddOn Author - Click to view addons
Join Date: Jul 2012
Posts: 66
1. When in doubt; use parantesis:

IF a and b or c and not d...

IF (a and b) or (c and (not d))...

IF (a) and (b) or (c) and (not d)...

2. You can always use nesting of IF's.

IF a and b 
    IF c 
    ElseIF not d
My main thing is always to make the code readable and understandable for yourself (and others). Imagine coming back to the code 6 months from now when you dont remember anything about why it's there. Making it super-condenced most of the time just makes code convoluted, hard to understand and hard to maintain.

LUA uses the same approach as most other languages when dealing with AND/OR: short-circuiting inclusive logical disjunction on two expressions. In short this means that it will skip the evaluation of the second part of an AND/OR expression if the first one is true.

You can learn more about that by reading here; This is for VB.net that uses the opposite approach for AND/OR but has additional keywords (ANDALSO, ORELSE) that works like AND/OR in other languages.
OrElse: https://msdn.microsoft.com/en-us/library/ea1sssb2.aspx
AndAlso: https://msdn.microsoft.com/en-us/library/cb8x3kfz.aspx
Author of IfThen, Links in Chat
  Reply With Quote