Search for a mac-address in the Bridge-Host or ARP table to extract the interface

Hi folks.

In the following code snippet, it does not work when the MAC address does not exist in the Bridge Host table or ARP table to extract the corresponding interface.

Where is the error?

{
:local bridHost [/interface/bridge/host/print as-value]
:local arpTable [/ip/arp/print as-value]
:local iFace " "
# The following MACs are for testing purposes:
# :local macAddress "54:B7:BD:70:0F:B8" ; # This MAC does not exist in the bridge host table
:local macAddress "E0:CC:F8:E7:90:4A" ; # Yes, it does exist

:foreach id in=$bridHost do={
    :if (($macAddress = ($id->"mac-address")) and ([:len ($id->"on-interface")] > 0)) do={
        :set iFace ($id->"on-interface")
    } else={
        :foreach id2 in=$arpTable do={
            :if (($macAddress = ($id2->"mac-address")) and ([:len ($id2->"interface")] > 0)) do={
                :set iFace ($id2->"interface")
            } else={
                :set iFace "*no interface*"
            }
        }
    }
}
:put $iFace
}

Thanks.

A way to simplify it a little, similar to the last problem, break the logic into two modular parts:

{
:local bridHost [/interface/bridge/host/print as-value]
:local arpTable [/ip/arp/print as-value]
:local iFace "*no interface*"
# The following MACs are for testing purposes:
# :local macAddress "54:B7:BD:70:0F:B8" ; # This MAC does not exist in the bridge host table
:local macAddress "E0:CC:F8:E7:90:4A" ; # Yes, it does exist

:foreach id in=$bridHost do={
    :if (($macAddress = ($id->"mac-address")) and ([:len ($id->"on-interface")] > 0)) do={
        :set iFace ($id->"on-interface")
    }
}

:if ($iFace = "*no interface*") do={
    :foreach id2 in=$arpTable do={
        :if (($macAddress = ($id2->"mac-address")) and ([:len ($id2->"interface")] > 0)) do={
            :set iFace ($id2->"interface")
        } 
    }
}

:put $iFace
}

Or better still perhaps to join the two arrays together before you then do the matching, depending on which table you prefer to get the answer from.

I understand now, thanks for your help.