Shop OBEX P1 Docs P2 Docs Learn Events
imbedded for...next loops — Parallax Forums

imbedded for...next loops

ArchiverArchiver Posts: 46,084
edited 2003-01-10 18:05 in General Discussion
Alex-

Nested FOR-NEXT loops are valid on all Stamps. The BS1 is unique in
that it will allow specifying the variable associated with NEXT,
such as:

FOR i = 1 to 10
FOR j = 1 to 5
...
NEXT j
NEXT i

The above will generate a syntax error with any flavor of BS2*.
Instead, just do this:

FOR i = 1 to 10
FOR j = 1 to 5
...
NEXT
NEXT

The editor will figure out which variable the NEXT applies to, which
will be the variable specified by the latest, preceding FOR.

Standard disclaimer/Alternate response: I agree with Jon, Tracy, or
Al and defer to their explanations.

Regards,

Steve

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2003-01-10 03:00
    When I tried an imbedded for...next loop on my BS-2SX, it gave me a
    syntax error. The documentation says that it only works on a BS1
    (!!!)...is this really the case?

    --Alex
  • ArchiverArchiver Posts: 46,084
    edited 2003-01-10 03:12
    Embedded FOR...NEXT loops are certainly possible. This works:

    idx1 VAR Nib
    idx2 VAR Nib

    Main:
    FOR idx1 = 1 TO 5
    FOR idx2 = 1 TO 5
    DEBUG DEC1 idx1, ":", DEC1 idx2, " "
    NEXT
    DEBUG CR
    NEXT
    END

    -- Jon Williams
    -- Parallax

    In a message dated 1/9/2003 9:03:03 PM Central Standard Time,
    atl_guy1138@y... writes:

    > When I tried an imbedded for...next loop on my BS-2SX, it gave me a
    > syntax error. The documentation says that it only works on a BS1
    > (!!!)...is this really the case?
    >
    > --Alex



    [noparse][[/noparse]Non-text portions of this message have been removed]
  • ArchiverArchiver Posts: 46,084
    edited 2003-01-10 15:17
    --- In basicstamps@yahoogroups.com, "atl_guy1138 <atl_guy1138@y...>"
    <atl_guy1138@y...> wrote:
    > When I tried an imbedded for...next loop on my BS-2SX, it gave me a
    > syntax error. The documentation says that it only works on a BS1
    > (!!!)...is this really the case?
    >
    > --Alex


    Okay, i get it now...I was trying to specify which loop the 'next'
    applied to (i.e. 'next i'). Apparently the Stamp can figure that out
    by itself.

    thanks
    --Alex
  • ArchiverArchiver Posts: 46,084
    edited 2003-01-10 16:11
    It just adds unnecessary complexity to the compiler and prevents you from
    doing things like this that could lead to bad bugs:

    ( for illustration only)

    FOR idx1 = x TO y
    ' some code
    FOR idx2 = x TO y
    ' some code
    NEXT idx1
    NEXT idx2

    You can accomplish what this code is trying to do by making the idx2 control
    loop the outer-most.

    -- Jon Williams
    -- Parallax

    In a message dated 1/10/2003 9:18:04 AM Central Standard Time,
    atl_guy1138@y... writes:

    > Okay, i get it now...I was trying to specify which loop the 'next'
    > applied to (i.e. 'next i'). Apparently the Stamp can figure that out
    > by itself.
    >
    > thanks
    > --Alex



    [noparse][[/noparse]Non-text portions of this message have been removed]
  • ArchiverArchiver Posts: 46,084
    edited 2003-01-10 18:05
    Your a good man John. I appreciate you being there for everyone, whether you
    get paid to do it or not.

    James


    On Fri, 10 Jan 2003 11:11:08 EST jonwms@a... wrote:

    > It just adds unnecessary complexity to the
    > compiler and prevents you from
    > doing things like this that could lead to bad
    > bugs:
    >
    > ( for illustration only)
    >
    > FOR idx1 = x TO y
    > ' some code
    > FOR idx2 = x TO y
    > ' some code
    > NEXT idx1
    > NEXT idx2
    >
    > You can accomplish what this code is trying to
    > do by making the idx2 control
    > loop the outer-most.
    >
    > -- Jon Williams
    > -- Parallax
    >
    > In a message dated 1/10/2003 9:18:04 AM Central
    > Standard Time,
    > atl_guy1138@y... writes:
    >
    > > Okay, i get it now...I was trying to specify
    > which loop the 'next'
    > > applied to (i.e. 'next i'). Apparently the
    > Stamp can figure that out
    > > by itself.
    > >
    > > thanks
    > > --Alex
    >
    >
    >
    > [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.