Skip to content

"foreach" Code Snippet

Foreach loop format & examples

Here is a quick reference showing both the format of a ":foreach" loop and code examples.

# Format:
:foreach <var> in=<array> do={ 
    <command>;
    <command>;
    ... 
}

RouterOS :foreach loop example:

# ":foreach" loop
:local MyFruit {"apples"; "plums"; "pears"};

# print out each fruit
:foreach Fruit in=$MyFruit do={
    :put "I like $Fruit as a snack";
}

Buy

Bookcover