Recommended Free Tools
Use Robot Framework’s current block syntax—FOR, an iteration marker such as IN or IN RANGE, the keyword calls to repeat, and a closing END—to repeat work over values. Choose ordinary IN for a list, IN RANGE for numbers, IN ENUMERATE when you need an index, and IN ZIP for paired collections. The examples below follow the Robot Framework User Guide 7.4.2.
Write a basic FOR loop
A loop variable receives one value per iteration. Put the repeated keyword calls inside the block and close it with END on its own row:
*** Test Cases ***
Process Items
FOR ${item} IN apple banana cherry
Log Processing ${item}
END
FOR and IN are case-sensitive markers. Indentation is recommended so the body is easy to distinguish, although the block boundary is defined by END.
Loop over a list variable
Expand a list variable with @{} in the loop header to iterate its elements:
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
#1 Best Overall
*** Test Cases ***
Process Items From List
@{items}= Create List apple banana cherry
FOR ${item} IN @{items}
Process Item ${item}
END
The example uses BuiltIn’s Create List keyword. The same FOR block form can be used inside test cases and user keywords.
Choose the loop form for your data
| Need | Form | What it does |
|---|---|---|
| Visit values or list elements | FOR ${item} IN @{items} |
Assigns each value to ${item} in sequence. |
| Generate numeric values | FOR ${i} IN RANGE 10 |
Iterates from 0 up to, but not including, 10. |
| Use both position and value | FOR ${i} ${item} IN ENUMERATE @{items} |
Assigns an index and the corresponding item; the index starts at 0 by default. |
| Process corresponding values from lists | FOR ${number} ${name} IN ZIP ${numbers} ${names} |
Assigns corresponding values from the lists to the loop variables. |
| Process dictionary entries | FOR ${key} ${value} IN &{dict} |
Assigns each dictionary key and value to separate variables. |
Numeric ranges with IN RANGE
A one-argument range begins at zero and excludes its end value, so IN RANGE 10 produces 0 through 9. You can also provide start, end, and step; the end remains excluded, and a negative step counts downward. Float parameters are permitted.
*** Test Cases ***
Visit Three Indexes
FOR ${index} IN RANGE 1 7 2
Log ${index}
END
This example visits 1, 3, and 5. Use a range when generating numbers is clearer than maintaining a list of them.
Keep an index with IN ENUMERATE
*** Test Cases ***
Log Items With Index
@{items}= Create List apple banana
FOR ${index} ${item} IN ENUMERATE @{items}
Log ${index}: ${item}
END
For a custom starting index, use start=<index>, documented from Robot Framework 4.0 onward:
FOR ${index} ${item} IN ENUMERATE @{items} start=1
Log ${index}: ${item}
END
Pair collections with IN ZIP
Use multiple loop variables to process related lists together:
*** Test Cases ***
Log Name And Number
@{numbers}= Create List 7 8
@{names}= Create List Ada Lin
FOR ${number} ${name} IN ZIP ${numbers} ${names}
Log ${name}: ${number}
END
Assign multiple values per iteration
A FOR header can declare multiple variables before the marker. With ordinary IN, the values must divide evenly among those variables. Use a dedicated form such as IN ENUMERATE or IN ZIP when it expresses the relationship more clearly.
Control execution and nest loops
Exit early or skip an iteration
BREAK exits the loop, while CONTINUE abandons the current iteration and proceeds to the next. They belong in the loop body, optionally inside an IF/ELSE or TRY/EXCEPT structure.
*** Test Cases ***
Skip And Stop
FOR ${item} IN skip keep stop later
IF '${item}' == 'skip'
CONTINUE
END
IF '${item}' == 'stop'
BREAK
END
Log ${item}
END
Do not put BREAK or CONTINUE inside a separate keyword called by the loop body; the User Guide says using them that way is invalid.
Nest loops for simple combinations
Nested FOR loops are supported from Robot Framework 4.0. For example, a simple row-and-cell traversal can use one loop inside another:
*** Test Cases ***
Visit Table Cells
@{rows}= Create List first second
@{cells}= Create List A B
FOR ${row} IN @{rows}
FOR ${cell} IN @{cells}
Log ${row} / ${cell}
END
END
Keep nested bodies short enough to read. The official guide advises that test libraries can implement loop constructs and that, most of the time, loops should be implemented in them; for complex test logic, move details into user keywords rather than building a hard-to-follow block in the test.
Use Repeat Keyword when one keyword is enough
If the only goal is to invoke one keyword a fixed number of times, a full FOR block may be unnecessary. BuiltIn’s Repeat Keyword accepts a repetition count and keyword arguments; readable count suffixes such as times or x are supported.
*** Test Cases ***
Repeat One Action
Repeat Keyword 3 times Click Button Save
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Use current syntax, not legacy :FOR
Older Robot Framework examples may show :FOR and backslashes to mark loop-body rows. That syntax was deprecated in Robot Framework 3.2 and removed in Robot Framework 4.0. For current code, use the block form with FOR and END. Nested FOR loops and the custom start=<index> option for IN ENUMERATE are also documented from version 4.0.
Troubleshoot common loop mistakes
- The loop block is not closed: Add
ENDon its own row after the repeated keywords. - A marker appears not to work: Check that
FOR,IN, and specialized markers are uppercase; the markers are case-sensitive. - The list is treated incorrectly: Use the expanded list variable form, such as
@{items}, in the loop header. - The final range number never appears: This is expected—
IN RANGEexcludes its end value. Adjust the end if that value should be included. - Multiple loop variables do not match the values: For ordinary
IN, ensure the number of values divides evenly among the declared variables. - BREAK or CONTINUE is rejected: Place it directly in the loop body, potentially within a control structure, rather than inside a called keyword.
- An old example fails on a current version: Replace the removed
:FORform with theFOR ... ENDblock syntax.
Or skip the browser setup
If your Robot Framework task is capturing website screenshots rather than learning loop syntax, ScreenshotNeo can return an image or PDF with one GET request. Its API documentation covers the available parameters.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
ScreenshotNeo removes cookie banners, newsletter popups, and chat widgets before capture; bot checks, blank pages, and failed loads are never billed. Its MCP server lets AI agents take screenshots. The Free plan includes 1,000 screenshots per month with no card, and paid plans start at $5 for 3,000. Sign up free.
Frequently Asked Questions
Can I use a FOR loop inside a user keyword?
Yes. The same block syntax is supported in test cases and user keywords.
Quick Recap
Does IN RANGE include its end value?
No. The range stops before the end value.
When were nested FOR loops added?
Robot Framework 4.0.
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.
Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Repair Windows errors before they cause bigger problemsFix Now →Scan for outdated or missing drivers - takes under a minuteDriver Scan →




