2 Replies Latest reply on Feb 13, 2014 10:46 PM by 4everJang

    Infinite loop with pgf.ObjectValid

    gisteppen

      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

        • 1. Re: Infinite loop with pgf.ObjectValid
          gisteppen Level 1

          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!

          • 2. Re: Infinite loop with pgf.ObjectValid
            4everJang Level 3

            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