Re: Q: DCL IF / NESTED IF-THEN-ELSE - VMS

This is a discussion on Re: Q: DCL IF / NESTED IF-THEN-ELSE - VMS ; "Ken Robinson" wrote on 11/12/2007 10:01:03 AM: > On Nov 12, 2007 9:39 AM, wrote: > > > > Here is a DCL gosub routine to pick a description > > out of an element list. If it does not ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: Re: Q: DCL IF / NESTED IF-THEN-ELSE

  1. Re: Q: DCL IF / NESTED IF-THEN-ELSE

    "Ken Robinson" wrote on 11/12/2007 10:01:03 AM:

    > On Nov 12, 2007 9:39 AM, wrote:
    > >
    > > Here is a DCL gosub routine to pick a description
    > > out of an element list. If it does not find
    > > a match in 1-5 is is supposed to set the LL
    > > index variable to zero and pick that one.
    > > Somehow, the statement to do that is not being
    > > executed. DCL_CHECK does not find any error.
    > >
    > > What am I missing?
    > >
    > > $FIND_TCODE: !Gosub
    > > $ LL=5
    > > $LOOPT:
    > > $ IF FCODE .NES. F$ELEMENT(LL,",",TCODE)
    > > $ THEN
    > > $ LL=LL+1
    > > $ show sym ll
    > > $ IF LL .LE. 5 THEN GOTO LOOPT
    > > $ ELSE
    > > $ IF LL .GT. 5 THEN LL=0
    > > $ ENDIF
    > > $ show sym ll
    > > $ RDESC=F$ELEMENT(LL,",",TDESC)
    > > $ RETURN

    >
    > The "endif" is in the wrong place. Also, shouldn't "TDESC" be "TCODE"
    > in "$ RDESC=F$ELEMENT(LL,",",TDESC)"?


    Well, the code certainly behaves as if the endif is in the wrong place,
    but it isn't. I will try structured if-the-else for all the
    if-statements and I'm sure that will fix it, but I suspect I have
    uncovered an ambiguity due to backward compatibility allowing
    if-then-else to be:

    $if then
    $endif

    instead of forcing:

    $if
    $then
    $
    $endif

    I would surely like to know what the expected behavior is, and
    if this violates the syntax. Too bad Charlie retired.

    And no, TDESC should be TDESC. It matches the code in one
    element table and move the description from another
    element table, but that's not relevent and since I didn't
    include that part of the procedure, you can't know that.

    >
    > Try:
    >
    > $FIND_TCODE: !Gosub
    > $ LL=5
    > $LOOPT:
    > $ IF FCODE .NES. F$ELEMENT(LL,",",TCODE)
    > $ THEN
    > $ LL=LL+1
    > $ show sym ll
    > $ IF LL .LE. 5 THEN GOTO LOOPT
    > $ endif
    > $ IF LL .GT. 5 THEN LL=0
    > $ show sym ll
    > $ RDESC=F$ELEMENT(LL,",",Tcode)
    > $ sho sym rdesc
    > $ RETURN
    >
    > Ken



  2. Re: Q: DCL IF / NESTED IF-THEN-ELSE

    On Nov 12, 2007 10:25 AM, wrote:
    >
    >
    >
    >
    > "Ken Robinson" wrote on 11/12/2007 10:01:03 AM:
    >
    >
    > > On Nov 12, 2007 9:39 AM, wrote:
    > > >
    > > > Here is a DCL gosub routine to pick a description
    > > > out of an element list. If it does not find
    > > > a match in 1-5 is is supposed to set the LL
    > > > index variable to zero and pick that one.
    > > > Somehow, the statement to do that is not being
    > > > executed. DCL_CHECK does not find any error.
    > > >
    > > > What am I missing?
    > > >
    > > > $FIND_TCODE: !Gosub
    > > > $ LL=5
    > > > $LOOPT:
    > > > $ IF FCODE .NES. F$ELEMENT(LL,",",TCODE)
    > > > $ THEN
    > > > $ LL=LL+1
    > > > $ show sym ll
    > > > $ IF LL .LE. 5 THEN GOTO LOOPT
    > > > $ ELSE
    > > > $ IF LL .GT. 5 THEN LL=0
    > > > $ ENDIF
    > > > $ show sym ll
    > > > $ RDESC=F$ELEMENT(LL,",",TDESC)
    > > > $ RETURN

    > >
    > > The "endif" is in the wrong place. Also, shouldn't "TDESC" be "TCODE"
    > > in "$ RDESC=F$ELEMENT(LL,",",TDESC)"?

    >
    > Well, the code certainly behaves as if the endif is in the wrong place,
    > but it isn't. I will try structured if-the-else for all the
    > if-statements and I'm sure that will fix it, but I suspect I have
    > uncovered an ambiguity due to backward compatibility allowing
    > if-then-else to be:
    >
    > $if then
    > $endif
    >


    That syntax is illegal


    > instead of forcing:
    >
    > $if
    > $then
    > $
    > $endif
    >
    > I would surely like to know what the expected behavior is, and
    > if this violates the syntax. Too bad Charlie retired.


    You original "if" block was (annotated by me)

    $ IF FCODE .NES. F$ELEMENT(LL,",",TCODE)
    $ THEN
    $ LL=LL+1
    $ show sym ll
    $ IF LL .LE. 5 THEN GOTO LOOPT
    $ ELSE ! this else goes with the original "IF" not the one above it
    $ IF LL .GT. 5 THEN LL=0 ! this line will only get executed
    when the original "if" is "false"
    $ ENDIF

    Ken



    >
    > And no, TDESC should be TDESC. It matches the code in one
    > element table and move the description from another
    > element table, but that's not relevent and since I didn't
    > include that part of the procedure, you can't know that.
    >
    >
    >
    > >
    > > Try:
    > >
    > > $FIND_TCODE: !Gosub
    > > $ LL=5
    > > $LOOPT:
    > > $ IF FCODE .NES. F$ELEMENT(LL,",",TCODE)
    > > $ THEN
    > > $ LL=LL+1
    > > $ show sym ll
    > > $ IF LL .LE. 5 THEN GOTO LOOPT
    > > $ endif
    > > $ IF LL .GT. 5 THEN LL=0
    > > $ show sym ll
    > > $ RDESC=F$ELEMENT(LL,",",Tcode)
    > > $ sho sym rdesc
    > > $ RETURN
    > >
    > > Ken

    >


+ Reply to Thread