Skip to content

"for" Code Snippet

For loop format & examples

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

# Format:
:for <var> from=<int> to=<int> [step=<int>] do={ 
    <command>;
    <command>;
    ...
}

RouterOS :for loop example:

# ":for" loop
:for LoopCount from=1 to=10 do={
    :put "Current loop count = $LoopCount";
    :delay 1;
}
# alternate example with step included
:for LoopCount from=1 to=100 step=10 do={
    :put "Current loop count = $LoopCount";
    :delay 1;
}

Buy

Bookcover