• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

multiple "if"/"or" conditions

Hi,
Im trying to write a task with multiple "if" conditions but every time i add another "if" it gets looped inside the first one. I can write the same task with an or Condition but i cant seem to find the option to do so.

Any ideas?

Thanks,
Edi.
 
You could try something like:


If Condition1
Do job 1
Do job 2
Else If Condition2 (Else, then tick the If box)
Do job 1
Do job 2
End If
End If


If there are a few jobs to perform, put them in another task.
It's not perfect but it should do the job.
 
Depending on what you want to do, you may want to create different profiles for your different required events, all pointing to the same task.
 
Boolean operators are not included in Tasker.

You can "and" by nesting if's.

Or is more challenging. As mentioned, you can put everything in a Task and call it from two separate if/then statements.

Here's another way.

If ConditionA Then
FlagA = 1
Else
FlagA = 0
End if

If ConditionB Then
FlagB = 1
Else
FlagB = 0
End if

If FlagA+FlagB > 0 Then
Popup "Condition A or Condition B is true"
Else
Popup "Neither condition A nor condition B is true"
End if

You should check "use maths" for this
 
Boolean operators are not included in Tasker.

You can "and" by nesting if's.

Or is more challenging. As mentioned, you can put everything in a Task and call it from two separate if/then statements.

Here's another way.

If ConditionA Then
FlagA = 1
Else
FlagA = 0
End if

If ConditionB Then
FlagB = 1
Else
FlagB = 0
End if

If FlagA+FlagB > 0 Then
Popup "Condition A or Condition B is true"
Else
Popup "Neither condition A nor condition B is true"
End if

You should check "use maths" for this
Nice! Never thought of that. Looking at it made me think of this also

If Condition A
Variable set %test ~ true
EndIF

If Condition B
Variable set %test ~ true
EndIF

If %test ~ true
Codition OR acheived
Else
Conditon OR not acheived
EndIF

Huge thanks! I've never given a workaround as much thought as you apparently have since OR is universal to everything else and lacking in Tasker. I'm sure I'll use this. Its much appreciated!



Also, to address some other stuff posted prior in the thread, you only need one Endif when using Else.

I've also found that I'm only able to nest so many if statements before they don't work. Its not that many before it starts to fail. The colors on the variables look correct when you look at the task but they don't work when the task runs so its something to look out for @OP. I think you have to go 3 or 4 deep before its a problem.
 
PDJ - Thank you for the thanks.
Nice! Never thought of that. Looking at it made me think of this also

If Condition A
Variable set %test ~ true
EndIF

If Condition B
Variable set %test ~ true
EndIF

If %test ~ true
Codition OR acheived
Else
Conditon OR not acheived
EndIF
That's a good alternative. I'm sure you assumed @test was initialized as %false.

My preference is still to stick with 1's and 0's.
Often times you'll need to store the intermediate condition test as a logical variable anyway. For example when a condition is tested at one time and the result used a a later time. Or maybe the result needs to be used in multiple places. So when you need to create a logical variable, I suggest to just code it as 1 or 0 to make it easier whenever you want to use that logical variable in a complicated expression later.

Example:
Let's say you want to OR not just two conditions but three and your logical variables are stored as 1's or 0's
You can simply use if if(FlagA + FlagB + FlagC) > 0.

More Complicated Example
Let's say you want the expression: If (A OR B OR C) AND D AND F AND NOT(G)
If all the logical variables are defined as 1's and 0's, you can do it as follows:
if(FlagA + FlagB + FlagC)*FlagD*FlagE*(ABS(FlagG-1)) > 0.

Note that
AND translates seamlessly to *
NOT translates seamlesslyto ABS(Flag - 1)
OR tranlslates to (Flag + Flag + Flag...) > 0

Note that the AND and NOT can be easily embedded in an expression without regard to where the expression is used (could be subexpression of bigger expression). The OR requires use of the comparison (>) operator which is only available within an IF statement argument. I'm trying to think if there is another way to do the OR using only the Tasker math operators (not the >). I guess if you needed we could use the following to give a logical OR:
ceil((FlagA + FlagB + FlagC...) / 100)
 
PDJ - Thank you for the thanks.

That's a good alternative. I'm sure you assumed @test was initialized as %false.

My preference is still to stick with 1's and 0's.
Often times you'll need to store the intermediate condition test as a logical variable anyway. For example when a condition is tested at one time and the result used a a later time. Or maybe the result needs to be used in multiple places. So when you need to create a logical variable, I suggest to just code it as 1 or 0 to make it easier whenever you want to use that logical variable in a complicated expression later.

Example:
Let's say you want to OR not just two conditions but three and your logical variables are stored as 1's or 0's
You can simply use if if(FlagA + FlagB + FlagC) > 0.

More Complicated Example
Let's say you want the expression: If (A OR B OR C) AND D AND F AND NOT(G)
If all the logical variables are defined as 1's and 0's, you can do it as follows:
if(FlagA + FlagB + FlagC)*FlagD*FlagE*(ABS(FlagG-1)) > 0.

Note that
AND translates seamlessly to *
NOT translates seamlesslyto ABS(Flag - 1)
OR tranlslates to (Flag + Flag + Flag...) > 0

Note that the AND and NOT can be easily embedded in an expression without regard to where the expression is used (could be subexpression of bigger expression). The OR requires use of the comparison (>) operator which is only available within an IF statement argument. I'm trying to think if there is another way to do the OR using only the Tasker math operators (not the >). I guess if you needed we could use the following to give a logical OR:
ceil((FlagA + FlagB + FlagC...) / 100)

That's quite elegant. As someone who started using Tasker only a month or so ago and can barely script apart from bash, I'm impressed with myself for understanding it. Bookmarking the page.
 
Back
Top Bottom