Whoops, never mind, I had a misplaced end bracket of the while. This is fixed now:
var doc = app.ActiveDoc;
var pgf = doc.MainFlowInDoc.FirstTextFrameInFlow.FirstPgf;
while ( pgf.ObjectValid() ) {
Console('Hello');
pgf = pgf.NextPgfInFlow;
}
I learned a new way to do an infinite loop!