How would you build a grid using a nested foreach, defining one node for each iteration?
If I were coding in Python, I would write:
nodes = {}
for i in range(10):
for j in range(5):
node = nodes[(i, j)] = create_node(location=(i, j), text="node text")
if (i-1, j) in nodes:
add_path(nodes[(i-1, j)], node, style=hstyle)
if (i, j-1) in nodes:
add_path(nodes[(i, j-1)], node, style=vstyle)
My code needs to be more complicated than this (it's not a simple grid), but doing this would be a great start.
add_path
calls, which I am using as a Python equivalent of tikz'spath
.