Wrapping a compound query around a loop.

From semantic-mediawiki.org