Script for make Address List from route table

hi
This is script for make address list from any route table. Version of RouterOS 7.15.3

:local size 0;
:local checkIP 0;
:local ipAddress ;
#Name of source table for import prefix's 
:local BGPIN 6G;
#Name of new Address List
:local ADList BGP_YOUTUBE;

#route ip address
/ip route
:foreach size in=[find where routing-table=$BGPIN] do={
:local ipAddress [get $size dst-address]

#:local checkIP [/ip firewall address-list print count-only where list=$ADList address=$ipAddress];
#if it is the default gateway don't add it

:if ($ipAddress=0.0.0.0/0) do={:set checkIP 2}

#If the IP is not in the list add it

:if ($checkIP = 0) do={
/ip firewall address-list add list=$ADList address=$ipAddress;}
}

Wrong for various reasons. Also superfluos ; , unconsistent variables name, etc.
For example, one above all, if on the foreach checkIP is set to 2, then it will never return to 0.
{
:local routingTable “6G”
:local addressList “BGP_YOUTUBE”
:local dstAddress 0.0.0.0

/ip route
:foreach item in=[find where routing-table=$routingTable] do={
    :local dstAddress [get $item dst-address]
    :if ($dstAddress!=0.0.0.0/0) do={
        /ip firewall address-list
        :if ([:len [find where list=$addressList and address=$dstAddress]] = 0) do={
            add list=$addressList address=$dstAddress
        }
    }
}

}