Skip to main content
gisteppen
Known Participant
February 13, 2014
Question

Infinite loop with pgf.ObjectValid

  • February 13, 2014
  • 1 reply
  • 562 views

Why would this result in an infinite loop? I thought that wehn it got to the last Pgf object it should become invalid and stop.

    var doc = app.ActiveDoc;

    var pgf = doc.MainFlowInDoc.FirstTextFrameInFlow.FirstPgf;

    while ( pgf.ObjectValid() ) {

        Console('Hello');

    }

    pgf = pgf.NextPgfInFlow;

Thanks,

Mark

This topic has been closed for replies.

1 reply

gisteppen
gisteppenAuthor
Known Participant
February 13, 2014

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!

4everJang
Legend
February 14, 2014

Hi Mark,

After I ran into this and similar problems a couple of times, I changed my styling to always put the opening curly bracket on the next line. In that way, the closing bracket is at the same indentation level. Makes it much easier to spot an enclosion error.

while ( condition )

{

     if ( other condition )

     {

          do something;

     }

     else

     {

          do something else;

     }

     get next item;

}

More whitespace, but that is not an issue for the computer.

Kind regards

Jang