Page 1 of 1

Can you use "else" multiple times in an IF Statement?  Topic is solved

Posted: 13 Aug 2018, 00:45
by TigerYT
For example:

Code: Select all

*Z::
    toggle := !toggle
    if (toggle) {
      SendInput, 1 
    }
    else {
      SendInput, 2
    }
Return
Would this work?

Code: Select all

*X::
    toggle := !toggle
    if (toggle) {
      SendInput, 1 
    }
    else {
      SendInput, 2
    }
    else {
      SendInput, 3
    }
    else {
      SendInput, 4
    }
    else {
      SendInput, 5
    }
Return

Re: Can you use "else" multiple times in an IF Statement?

Posted: 13 Aug 2018, 01:21
by Alibaba
No it wouldn’t. If always evaluates to true, then it will continue execution in the if block, or to false, then it continues in the else block. There are always exactly two cases, your example shows five different cases. Maybe you are looking for nested ifs, or else if.

Code: Select all

if (var = "A")
{
    Send A
    ...
}
else if (var = "B")
{
    Send B
    ...
}
else if (var = "C")
{
    Send C
    ...
}
else
{
    Send X
    SoundBeep
}

Re: Can you use "else" multiple times in an IF Statement?

Posted: 13 Aug 2018, 01:29
by Alibaba
Please don’t open multiple topics with the same question. If you are posting as a guest you will have to wait for the topic approval and duplicating topics will only result in extra work for the moderation team, but not in a faster approval.
The time it takes the moderation team to check posts is depending on the current activity, so there are no guarantees. Consider registering an account. Once your account is approved you can post topics without waiting time.

Greetings,
Alibaba

Re: Can you use "else" multiple times in an IF Statement?

Posted: 13 Aug 2018, 03:56
by TigerYT
Alibaba wrote:Please don’t open multiple topics with the same question. If you are posting as a guest you will have to wait for the topic approval and duplicating topics will only result in extra work for the moderation team, but not in a faster approval.
The time it takes the moderation team to check posts is depending on the current activity, so there are no guarantees. Consider registering an account. Once your account is approved you can post topics without waiting time.

Greetings,
Alibaba
I didn't post multiple times. :?

Re: Can you use "else" multiple times in an IF Statement?

Posted: 13 Aug 2018, 05:05
by Alibaba
Well there where three topics called all the same, by a guest account called "TigerYT", i deleted two of them.

Re: Can you use "else" multiple times in an IF Statement?

Posted: 13 Aug 2018, 05:34
by TigerYT
Oh, Well maybe I clicked the 'submit' button multiple times and it didn't register as one topic?

Re: Can you use "else" multiple times in an IF Statement?

Posted: 13 Aug 2018, 13:22
by Alibaba
Whatever it was, it’s not that big of a deal, we won’t punish you for it. :D
Just watch out next time. :)