Shop OBEX P1 Docs P2 Docs Learn Events
Help on If-Then-Gosub — Parallax Forums

Help on If-Then-Gosub

ArchiverArchiver Posts: 46,084
edited 2002-11-13 02:01 in General Discussion
Hi,

How do you go directly to a gosub from a If - Then statement?
ie If 10 > 5 Then Task1
How do you Gosub Task1 ie. If 10 > 5 Then Gosub Task1 ( Which is not
allowed )

Thanks Stuart




[noparse][[/noparse]Non-text portions of this message have been removed]

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2002-11-12 16:13
    --- stuarttttt@a... wrote:
    > Hi,
    > How do you go directly to a gosub from a If -
    > Then statement?
    > ie If 10 > 5 Then Task1
    > How do you Gosub Task1 ie. If 10 > 5 Then
    > Gosub Task1 ( Which is not
    > allowed )

    Hi Stuart...

    You could do something like this:

    Main:
    :[noparse]:o[/noparse]ther code
    if 10 > 5 then Task1
    :[noparse]:o[/noparse]ther code::
    goto Main


    Task1:
    gosub TaskSub
    goto wherever

    TaskSub:
    your subroutine here
    return



    =====
    Chris Savage
    Knight Designs
    324 West Main Street
    Montour Falls, NY 14865
    (607) 535-6777

    http://www.knightdesigns.com

    __________________________________________________
    Do you Yahoo!?
    U2 on LAUNCH - Exclusive greatest hits videos
    http://launch.yahoo.com/u2
  • ArchiverArchiver Posts: 46,084
    edited 2002-11-12 16:34
    Yes but.......after the "RETURN" the program only takes you back to Task1 and
    not to the programme line directly after the If-Then statement, this is where
    I would like to go back to. Any other thoughts, there must be some way ??
    Stuart

    > --- stuarttttt@a... wrote:
    > > Hi,
    > > How do you go directly to a gosub from a If -
    > > Then statement?
    > > ie If 10 > 5 Then Task1
    > > How do you Gosub Task1 ie. If 10 > 5 Then
    > > Gosub Task1 ( Which is not
    > > allowed )
    >
    > Hi Stuart...
    >
    > You could do something like this:
    >
    > Main:
    > :[noparse]:o[/noparse]ther code
    > if 10 > 5 then Task1
    > :[noparse]:o[/noparse]ther code::
    > goto Main
    >
    > Task1:
    > gosub TaskSub
    > goto wherever
    >
    > TaskSub:
    > your subroutine here
    > return
    >
    >





    [noparse][[/noparse]Non-text portions of this message have been removed]
  • ArchiverArchiver Posts: 46,084
    edited 2002-11-12 16:48
    --- stuarttttt@a... wrote:
    > Yes but.......after the "RETURN" the program only
    > takes you back to Task1 and
    > not to the programme line directly after the If-Then
    > statement, this is where
    > I would like to go back to. Any other thoughts,
    > there must be some way ??

    Well, the only other idea I have in that case, is to
    put a Label after the IF THEN line, then have the
    Task1 line do a GOTO that label...Depending on how
    many places you need to do this in your program, it
    could work.




    =====
    Chris Savage
    Knight Designs
    324 West Main Street
    Montour Falls, NY 14865
    (607) 535-6777

    http://www.knightdesigns.com

    __________________________________________________
    Do you Yahoo!?
    U2 on LAUNCH - Exclusive greatest hits videos
    http://launch.yahoo.com/u2
  • ArchiverArchiver Posts: 46,084
    edited 2002-11-12 17:14
    If I understand your question, the trick is to reverse the sense of the
    test. So instead of:

    If 10>5 then Gosub Task1

    Try:

    If 10<=5 then NotIf1
    Gosub Task1
    NotIf1:

    You can extend this to an else like structure:

    If 10<=5 then ElseIf1
    Gosub Task1
    Goto NotIf1:
    ElseIf1:
    Gosub Task2
    NotIf1:

    This is the same as:

    If 10>5 then Gosub Task1 Else Gosub Task2

    I did a project of the month a while back that was a preprocessor that
    did this among other things.

    Regards,

    Al Williams
    AWC
    * Easy RS-232 Prototyping
    http://www.al-williams.com/awce/rs1.htm



    >
    Original Message
    > From: stuarttttt@a... [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=9Kupm08Hg9baMu8-VESLvUIZFqf93Ygk9SF6AkTxmOufWjlUs8HhOU9-MJvL_LpPIwJ3ZYtdLgPUwQ]stuarttttt@a...[/url
    > Sent: Tuesday, November 12, 2002 10:34 AM
    > To: basicstamps@yahoogroups.com
    > Subject: [noparse][[/noparse]JUNK] Re: [noparse][[/noparse]basicstamps] Help on If-Then-Gosub
    >
    >
    > Yes but.......after the "RETURN" the program only takes you
    > back to Task1 and
    > not to the programme line directly after the If-Then
    > statement, this is where
    > I would like to go back to. Any other thoughts, there must
    > be some way ?? Stuart
    >
    > > --- stuarttttt@a... wrote:
    > > > Hi,
    > > > How do you go directly to a gosub from a If -
    > > > Then statement?
    > > > ie If 10 > 5 Then Task1
    > > > How do you Gosub Task1 ie. If 10 > 5 Then
    > > > Gosub Task1 ( Which is not
    > > > allowed )
    > >
    > > Hi Stuart...
    > >
    > > You could do something like this:
    > >
    > > Main:
    > > :[noparse]:o[/noparse]ther code
    > > if 10 > 5 then Task1
    > > :[noparse]:o[/noparse]ther code::
    > > goto Main
    > >
    > > Task1:
    > > gosub TaskSub
    > > goto wherever
    > >
    > > TaskSub:
    > > your subroutine here
    > > return
    > >
    > >
    >
    >
    >
    >
    >
    > [noparse][[/noparse]Non-text portions of this message have been removed]
    >
    >
    > To UNSUBSCRIBE, just send mail to:
    > basicstamps-unsubscribe@yahoogroups.com
    > from the same email address that you subscribed. Text in the
    > Subject and Body of the message will be ignored.
    >
    >
    > Your use of Yahoo! Groups is subject to
    > http://docs.yahoo.com/info/terms/
    >
    >
    >
  • ArchiverArchiver Posts: 46,084
    edited 2002-11-12 18:55
    And another way is to put the test and branch in the subroutine:

    gosub tasktest
    continue here on return

    tasktest:
    if 10>5 then task1
    return ' not do it

    task1:
    'do it
    return

    That works well with BRANCH:

    gosub tasktest
    ' continue here on return

    tasktest:
    lookdown x,>[noparse][[/noparse]0,10,57],index ' several possibilities
    branch index,[noparse][[/noparse]task0,task1,task2]
    return ' should never get here

    task0:
    'do it
    return

    task1:
    'do it
    return

    task2:
    'do it
    return


    >If I understand your question, the trick is to reverse the sense of the
    >test. So instead of:
    >
    >If 10>5 then Gosub Task1
    >
    >Try:
    >
    >If 10<=5 then NotIf1
    >Gosub Task1
    >NotIf1:
  • ArchiverArchiver Posts: 46,084
    edited 2002-11-13 02:01
    Hi Stuart,

    Test the other way round, like
    if 10<=5 then skipline
    ::gosub task:
    skipline:

    regards peter



    Oorspronkelijk bericht
    Van: stuarttttt@a... [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=_oPeXaVClca8IYSAPYpEbBqIBcguMtJlw3Y0dY4VQlvgGfnE7qinIS5kk3nyeQUFrze9kFx0_i8k]stuarttttt@a...[/url
    Verzonden: dinsdag 12 november 2002 08:34
    Aan: basicstamps@yahoogroups.com
    Onderwerp: Re: [noparse][[/noparse]basicstamps] Help on If-Then-Gosub

    Yes but.......after the "RETURN" the program only takes you back to Task1
    and
    not to the programme line directly after the If-Then statement, this is
    where
    I would like to go back to. Any other thoughts, there must be some way ??
    Stuart

    > --- stuarttttt@a... wrote:
    > > Hi,
    > > How do you go directly to a gosub from a If -
    > > Then statement?
    > > ie If 10 > 5 Then Task1
    > > How do you Gosub Task1 ie. If 10 > 5 Then
    > > Gosub Task1 ( Which is not
    > > allowed )
    >
    > Hi Stuart...
    >
    > You could do something like this:
    >
    > Main:
    > :[noparse]:o[/noparse]ther code
    > if 10 > 5 then Task1
    > :[noparse]:o[/noparse]ther code::
    > goto Main
    >
    > Task1:
    > gosub TaskSub
    > goto wherever
    >
    > TaskSub:
    > your subroutine here
    > return
    >
    >





    [noparse][[/noparse]Non-text portions of this message have been removed]


    To UNSUBSCRIBE, just send mail to:
    basicstamps-unsubscribe@yahoogroups.com
    from the same email address that you subscribed. Text in the Subject and
    Body of the message will be ignored.


    Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
Sign In or Register to comment.