do while(1) construct?

Reply
Frequent Contributor
Posts: 75

do while(1) construct?

i'm failing to understand the do while(1) construct, 1 in () does it mean anything in the expression without referencing a variable name in the do while(expression)

data w ( keep = date time cond species vers hdr x1 - x9 ) ;

           format date date7. time time12.2 ;

           infile cards truncover eof = fini ;

           input @'date ' datec $char9.

                  @'time ' time :time11.

                / @'Condition: ' cond $char20.

                / @'Species: ' species $8.

                / @'version: ' vers $8.

                / @'information: ' hdr $20.

                / ;

           /* will the software produce bad dates in 2+ years??? */

           date = input ( compress ( datec,'-'), date7. ) ;

          do while ( 1 ) ; /* what does this expression mean?*/

              input ( x1 - x9 ) ( :$20. ) ;

              output ;

           end ;

        return ;

        fini:

        return ;

        cards ;

        date 10-jan-95 time 05:20.36.44

        Condition: blah, blah, blah,

        Species: 4LA

        Software version: xxx.xx

        Other header information: aaaa.a bbbbb.b

        operators-who-collected-the-data...

          x y x az el ra speed direction, etc.

          x y x az el ra speed direction, etc.

          x y x az el ra speed direction, etc.

          x y x az el ra speed direction, etc.

          x y x az el ra speed direction, etc.

        ;

Respected Advisor
Posts: 3,790

Re: do while(1) construct?

The expression evaluated is 1, TRUE.  It means do forever.  The thing you need to know is why doesn't it actually do forever.  For that look at INFILE statement options EOF= and UNBUFFERED.

PROC Star
Posts: 7,439

Re: do while(1) construct?

The do while(1) will simply keep reading and outputting your x1-x9 values until it reaches an end of file. It is simply saying do while(true)

Yes, you will run into problems if your date ever contains a 4 digit year.

And, if your times are really in the format shown in your example, they will have to be modified before input as well.

e.g.,

data w ( keep = date time cond species vers hdr x1 - x9 ) ;

           informat datec $char11.;

           informat timec $char11.;

           format date date7.;

           format time time12.2 ;

           infile cards truncover eof = fini ;

           input @'date ' datec

                  @'time ' timec

                / @'Condition: ' cond $char20.

                / @'Species: ' species $8.

                / @'version: ' vers $8.

                / @'information: ' hdr $20.

                / ;

           /* will the software produce bad dates in 2+ years??? */

           date = input ( compress ( datec,'-'), anydtdte9. ) ;

           substr(timec,index(timec,'.'),1) = ':';

           time=input(timec,time11.);

          do while ( 1 ) ; /* what does this expression mean?*/

              input ( x1 - x9 ) ( :$20. ) ;

              output ;

           end ;

        return ;

        fini:

        return ;

        cards ;

        date 10-jan-2014 time 05:20.36.44

        Condition: blah, blah, blah,

        Species: 4LA

        Software version: xxx.xx

        Other header information: aaaa.a bbbbb.b

        operators-who-collected-the-data...

          x y x az el ra speed direction, etc.

          x y x az el ra speed direction, etc.

          x y x az el ra speed direction, etc.

          x y x az el ra speed direction, etc.

          x y x az el ra speed direction, etc.

        ;

Frequent Contributor
Posts: 75

Re: do while(1) construct?

cool. Thanks Art and DN. Is there any specific document or link can you point me to for more and complete information on such do loop constructs particularly mentioning different ways to write expressions to use in do loop constructs unlike the convention as well as like using set inside a do loop, do _n_= as index variable and so on ? I have read through some on some docs found online but my grasping to this kind isn't quickSmiley Sad  Sorry for the bother

Mark

PROC Star
Posts: 7,439

Re: do while(1) construct?

Mark: Post an example of the data you are trying to read and it will be a lot easier to point you in the right direction.

Ask a Question
Discussion stats
  • 4 replies
  • 257 views
  • 6 likes
  • 3 in conversation