🔄 Mastering Uniface's forlist...endfor Loop: A Developer's Guide
Peter + AI

Peter + AI @petercode

Joined:
Jul 12, 2025

🔄 Mastering Uniface's forlist...endfor Loop: A Developer's Guide

Publish Date: Jul 18
0 0

Hey developers! 👋 Today I want to share something cool about Uniface's loop handling that might help you write cleaner, more efficient code. With the assistance of AI, I've put together this comprehensive guide based on the Uniface documentation 10.4.

🎯 What is forlist...endfor?

The forlist...endfor statement in Uniface is a powerful loop construct that processes all items in an indexed list. Think of it as Uniface's version of a foreach loop, but with some unique characteristics that make it particularly useful for handling Gold-separated lists.

📋 Syntax Breakdown

forlist Item {, Index} in SourceList 
  Your ProcScript 
endfor
Enter fullscreen mode Exit fullscreen mode

Parameters 📝

Parameter Data Type Description
Item String Current list item being processed
Index Number Item number in list (optional)
SourceList String Variable or field containing Uniface (Gold-separated) list

🚀 How It Works

The loop continues executing until one of these conditions is met:

  • 📊 Item number exceeds the last item number
  • 🔢 Index exceeds the last item number
  • 🛑 A break statement is encountered

After completion, the Index holds the value of the last item number + 1, or the last item reached before a break statement.

💡 Practical Example

Here's a real-world example that searches through a list of ancient cities until it finds "Pompey":

variables
 string vList
 string vItem
 numeric vIndex
endvariables

vList = "Athens;Rome;Syracuse;Pompey;Sparta"

forlist vItem, vIndex in vList 
 if (vItem = "Pompey")
 putmess "Loop processing stopped on Item number: %%vIndex, Value: %%vItem"
 break
 endif
 putmess "Processing Item number: %%vIndex, Value: %%vItem"
endfor
Enter fullscreen mode Exit fullscreen mode

🖥️ Expected Output:

Processing Item number: 1, Value: Athens
Processing Item number: 2, Value: Rome
Processing Item number: 3, Value: Syracuse
Loop processing stopped on Item number: 4, Value: Pompey
Enter fullscreen mode Exit fullscreen mode

🎨 Key Features

  • 🔧 Flexible Index Control: You can modify the Index within the loop for conditional processing
  • 🏗️ Universal Compatibility: Works in all Uniface component types
  • Early Exit: Support for break statements to optimize performance
  • 📝 Clean Syntax: Readable and maintainable code structure

🔥 Pro Tips

  • 🎯 Use the Index parameter when you need to track position or implement conditional logic
  • 🚀 Leverage break statements to exit early when your condition is met
  • 🔄 Remember that Gold-separated lists are the standard format for SourceList
  • 🛠️ The Index can be modified within the loop for advanced control flow

✅ Conclusion

The forlist...endfor loop is an essential tool in any Uniface developer's toolkit. Its flexibility and power make it perfect for processing lists efficiently while maintaining clean, readable code. Whether you're iterating through database results, processing user input, or handling configuration data, this loop construct has you covered! 🎉

Happy coding! 💻✨

Comments 0 total

    Add comment