Community discussions

MikroTik App
 
tik4jn
just joined
Topic Author
Posts: 8
Joined: Wed Apr 13, 2016 5:15 pm

Multiple If Statements

Wed Mar 03, 2021 5:44 pm

Hello!

I'm having an issue when using multiple IF statements. The code doesn't seem to run :
:log info "Hi"
:local a 1
:local b 2
:local c 3


:if ($a=1) do={
:log info "A is definitely 1"} else={
:if ($a=2) do={
:log info "A is definitely 2"} else={
:log info "A is not 1 or 2"}
BUT if we remove the second if statement, the code runs perfectly fine:
:log info "Hi"
:local a 1
:local b 2
:local c 3


:if ($a=1) do={
:log info "A is definitely 1"} else={
:log info "A is not 1 or 2"}
What am i doing wrong?
 
Emil66
Frequent Visitor
Frequent Visitor
Posts: 62
Joined: Tue Aug 28, 2018 2:09 am

Re: Multiple If Statements  [SOLVED]

Wed Mar 03, 2021 6:01 pm

:if ($a=1) do={
:log info "A is definitely 1"} else={
:if ($a=2) do={
:log info "A is definitely 2"} else={
:log info "A is not 1 or 2"}

If you fix your formatting, the problem becomes obvious: You're missing a closing brace for the first else.
:if ($a=1) do={
    :log info "A is definitely 1"
} else={
    :if ($a=2) do={
        :log info "A is definitely 2"
    } else={
        :log info "A is not 1 or 2"
    }
 
tik4jn
just joined
Topic Author
Posts: 8
Joined: Wed Apr 13, 2016 5:15 pm

Re: Multiple If Statements

Wed Mar 03, 2021 6:09 pm

Wow. I feel stupid. Thank You!
:if ($a=1) do={
:log info "A is definitely 1"} else={
:if ($a=2) do={
:log info "A is definitely 2"} else={
:log info "A is not 1 or 2"}

If you fix your formatting, the problem becomes obvious: You're missing a closing brace for the first else.
:if ($a=1) do={
    :log info "A is definitely 1"
} else={
    :if ($a=2) do={
        :log info "A is definitely 2"
    } else={
        :log info "A is not 1 or 2"
    }

Who is online

Users browsing this forum: No registered users and 24 guests