Work around for exiting a loop?

I’m tyring to figure out how to break a loop when a condition is met. I have the following script working the way I’d like:

:global source [:tostr [/system resource usb get [/system resource usb find ports=0]]]
:local start ([:find $source “device-id=”] + [:len “device-id=”]); :local end [:find $source “,” $start]; :global deviceID [:pick $source $start $end]; :put $deviceID;

:global content [/file get [/file find name=test.txt] contents] ;
:global contentLen [ :len $content ] ;

:global lineEnd 0;
:global line “”;
:global lastEnd 0;

:do {

:set lineEnd [:find $content “\r\n” $lastEnd ] ;
:set line [:pick $content $lastEnd $lineEnd] ;
:set lastEnd ( $lineEnd + 2 ) ;


:local tmpArray [:toarray $line];

:if ([:pick $tmpArray 0] =$deviceID) do={
/interface ppp-client
add add-default-route=yes allow=pap,chap,mschap1,mschap2 comment=“”
data-channel=[:pick $tmpArray 2] dial-command=ATDT dial-on-demand=no disabled=no
info-channel=[:pick $tmpArray 3] keepalive-timeout=30 max-mru=1500 max-mtu=1500 modem-init=
“” mrru=disabled name=ppp-out1 null-modem=no password=“” phone=[:pick $tmpArray 1] pin=
“” port=usb profile=default use-peer-dns=yes user=“”;
}
} while ($lineEnd < $contentLen)

However I’d like it so that if there are no matches from tmpArray 0 from the test.txt file. A default ppp-client is added. If there is a match the default ppp-client is not added.

Thanks,

Here is a take on it:

/interface ppp-client {
    :local deviceID [/system resource usb get [find ports=0] device-id]
    :local content [/file get [find name=test.txt] contents]
    :local contentLen [:len $content]

    :local deviceFound false
    :local lineEnd 0;
    :local line "";
    :local lastEnd 0;
    :do {
        :set lineEnd [:find $content "\r\n" $lastEnd]
        :set line [:pick $content $lastEnd $lineEnd]
        :set lastEnd ($lineEnd + 2)

        :local tmpArray [:toarray $line]
        :if ([:pick $tmpArray 0] = $deviceID) do={
            add data-channel=[:pick $tmpArray 2] dial-on-demand=no disabled=no \
                info-channel=[:pick $tmpArray 3] name=ppp-out1 phone=[:pick $tmpArray 1] \
                port=usb
            :set deviceFound true
        }
    } while=($deviceFound || $lineEnd < $contentLen)
    
    :if ($deviceFound = false) do={
        add data-channel=0 dial-on-demand=no disabled=no \
            info-channel=0 name=ppp-out1 phone=19315551234 port=usb
    }
}