I don’t know how and why this piece of code works:
// postorder dfs
Iterator< Index<String<char> >, TopDown<ParentLink<Postorder> > >::Type
myIterator(myIndex);
while (goDown(myIterator));
for (; !atEnd(myIterator); goNext(myIterator))
// do something with myIterator ( Traverse Through (Suffix)-tree )
It’s an example from seqan and the interface is described here: API
- How can the while affect the for-loop?
- Why isn’t the for loop initialized?
You’ve run into the fun parts of C++ – using language constructs in syntactically valid but difficult-for-human-parsing techniques.
This will “goDown(myIterator)” until it returns false. Then it will continue onto the for loop. It’s looping over nothing – but that’s okay, because the function goDown is doing work.
This doesn’t initialize anything, but tests that it’s not atEnd(myIterator) – while it’s not, it will goNext(myIterator). It could also be written as a while loop to make it slghtly easier to understand:
So the code will: