How can I dynamically loop through a web table or list of elements when the count is not fixed (for example, unknown number of rows or XPath like //*[@class="item"][1..n])?

I don’t want to hardcode the index (like 1 to 6).
What is the best approach