Dear All, This is with reference to the explanation of foreach loop in Overpass QL on the following page: query about foreach loop Query 1: Inside foreach loop, does ._ refer to one item in the set _ in the global namespace? For example in this snippet:
Here way[name="Foo"]; will put every way with the name ="Foo" in the default set _ . Then foreach will loop over each way in _ ( the global default set) and at each iteration of the foreach loop ._ (inside the foreach loop) refers to ONE way with the name ="Foo" ie ONE way in the global default set.It is taking the union of that ONE way with the nodes constituting that particular way. Whereas in the following code:
Out here ._ is the set containing ALL the ways with name="Foo". Do I understand correctly? The meaning of ._ is different when it is within the foreach loop and when it is outside the foreach loop. Is that correct? Its something like a global vs a local variable. Query 2: In this snippet :
The foreach will loop over the global _ and put each way in the global _ in _ (which is local to the foreach) and place the result of (union of local _ and it's nodes ) (._ ;>;); in _ which is local to the foreach and is NOT the global default set. The out will refer to this local _ and print out the contents of the local _ . Is this correct? Query 3: It says that the following snippet of code (from here, once again link:query about foreach loop):-
will do the following: For each way that has a name tag with value "Foo", this prints the nodes that belong to this way immediately followed by the way itself. I think the order is the other way round. It seems to me that it will first print each way with the name tag with value Foo and then print the nodes that belong to this way. Reason : inside the union in foreach loop we have (._;>;); which FIRST has the way and THEN the nodes and not the other way round. Have I misunderstood how this works? asked 08 Feb '18, 10:43 ashimkapoor scai ♦ |