Loops and Iteration Examples in Zolt
Basic Loop
Simple iteration over an array:
Loop with Index
Access loop index variables:
- Laptop: $999
- Mouse: $29
- Keyboard: $79
Loop with Index1
1-based indexing:
- Laptop
- Mouse
- Keyboard
Loop Variables
Available automatic variables:
| Variable | Description |
{$foreach.index} | Current index (0-based) |
{$foreach.index1} | Current index (1-based) |
{$foreach.first} | true if first element |
{$foreach.last} | true if last element |
{$foreach.even} | true if index is even |
{$foreach.odd} | true if index is odd |
First and Last Detection
🏆 Featured Product: Laptop
Mouse
Clearance Item: Keyboard
Even and Odd Styling
Alternate row colors:
Nested Loops
Categories with products:
Technology
Home & Garden
Loop with Condition
Filter products by price:
Loop with Counter
Odd step: Task 1 Even step: Task 2 Odd step: Task 3 Even step: Task 4
Practical Examples
Team Roster
Team Members
- ✅ Alice (Developer)
- ✅ Bob (Designer)
User List
User Directory
👤 John (Admin)
Email: john@example.com
👤 Jane
Email: jane@example.com
👤 Bob
Email: bob@example.com
Last updated: 26/02/2026 10:53:46
Current Stock
Widget A
- Quantity: 50
- Price: $19.99
- Value: $999.5
Widget B
- Quantity: 30
- Price: $29.99
- Value: $899.7
⚠️ Low stock! Widget C
- Quantity: 100
- Price: $9.99
- Value: $999
FAQ with Categories
General
What is Zolt?
A modern markup language.
Is it free?
Yes, completely open source.
Technical
How do I install?
Run: npm install zolt-cli
HTML, PDF, EPUB
Home About Services Contact
Progress Tracker
- ✅ Planning - Complete
- ✅ Design - Complete
- ⏳ Development - In Progress
- ⏳ Testing - In Progress
- ⏳ Deployment - In Progress
Image Gallery

*Photo by John*

*Photo by Jane*

*Photo by Bob*
Data Table
| Rank | Name | Score |
| 1 | Alice | 95 |
| 2 | Bob | 87 |
| 3 | Charlie | 92 |
Changelog Generator
Changelog
v2.0.0 (2026-02-01)
v1.9.0 (2026-01-15)
v1.8.0 (2026-01-01)
Card Grid
🎨 Card 1
⚡ Card 2
🚀 Card 3
Complex Examples
Nested Categories and Subcategories
Task Board
To Do
In Progress
Done
Weekly Schedule
Monday
- 9:00 AM: Meeting
- 10:00 AM: Meeting
- 11:00 AM: Meeting
Tuesday
- 9:00 AM: Meeting
- 10:00 AM: Meeting
- 11:00 AM: Meeting
Wednesday
- 9:00 AM: Meeting
- 10:00 AM: Meeting
- 11:00 AM: Meeting
Thursday
- 9:00 AM: Meeting
- 10:00 AM: Meeting
- 11:00 AM: Meeting
Friday
- 9:00 AM: Meeting
- 10:00 AM: Meeting
- 11:00 AM: Meeting
Loop Best Practices
Always Use Descriptive Variable Names
✅ Good:
:::foreach {$products as $product}
❌ Bad:
:::foreach {$items as $i}
Check for Empty Arrays
:::if {List.length($items) > 0}
:::foreach {$items as $item}
- {$item}
:::
:::
Limit Nested Loops
Too many nested loops can be hard to read. Consider restructuring.
Use Conditions Inside Loops
Filter and transform data as needed:
:::foreach {$items as $item}
:::if {$item.active}
- **{$item.name}**
:::
:::
:::
← Back to Examples Index