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

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
TigerYT

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

13 Aug 2018, 00:45

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
Alibaba
Posts: 480
Joined: 29 Sep 2013, 16:15
Location: Germany

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

13 Aug 2018, 01:21

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
}
"Nothing is quieter than a loaded gun." - Heinrich Heine
Alibaba
Posts: 480
Joined: 29 Sep 2013, 16:15
Location: Germany

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

13 Aug 2018, 01:29

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
"Nothing is quieter than a loaded gun." - Heinrich Heine
TigerYT
Posts: 24
Joined: 13 Aug 2018, 01:01

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

13 Aug 2018, 03:56

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. :?
Alibaba
Posts: 480
Joined: 29 Sep 2013, 16:15
Location: Germany

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

13 Aug 2018, 05:05

Well there where three topics called all the same, by a guest account called "TigerYT", i deleted two of them.
"Nothing is quieter than a loaded gun." - Heinrich Heine
TigerYT
Posts: 24
Joined: 13 Aug 2018, 01:01

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

13 Aug 2018, 05:34

Oh, Well maybe I clicked the 'submit' button multiple times and it didn't register as one topic?
Alibaba
Posts: 480
Joined: 29 Sep 2013, 16:15
Location: Germany

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

13 Aug 2018, 13:22

Whatever it was, it’s not that big of a deal, we won’t punish you for it. :D
Just watch out next time. :)
"Nothing is quieter than a loaded gun." - Heinrich Heine

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Descolada, jchestnut, Sem552 and 145 guests