Announcement

Collapse
No announcement yet.

Arrays

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Michael Mattias
    replied
    >That's different from what I learned years ago with other basics

    Which BASICs were those? I can't remember any BASIC which did NOT use 0-based subscripts by default.

    MCM

    Leave a comment:


  • Cliff Nichols
    replied
    Yes I did John, I just mis-spoke what I meant

    Leave a comment:


  • John Gleason
    replied
    Originally posted by Chris Holbrook View Post
    ...No idea what impact this has on performance, but it keeps my code looking simpler.
    Every test I've done shows it's faster too, in certain circumstances maybe even approaching 2x.

    Originally posted by Cliff Nichols
    DIM Array(20, 20)...would result in an array with 21 elements (1 to 20 based), but each element starts from a number one less than the count
    1 to 20 there gives only 20 elements, did you mean 1 to 21, based on "one less than the count" logic?

    Leave a comment:


  • Chris Holbrook
    replied
    It's not a bad discipline to use the full syntax when dimensioning arrays, for example, DIM SDFGHJKL(0 to 99).

    Regarding multidimensional arrays, for some reason I find it more natural to use a single dimension and multiply out the index. No idea what impact this has on performance, but it keeps my code looking simpler.

    Leave a comment:


  • Cliff Nichols
    replied
    It depends on zer0 based vs 1 based
    for details....as the rules depend on the application

    Generically though
    DIM Array(20, 20)
    would result in an array with 21 elements (1 to 20 based), but each element starts from a number one less than the count

    Leave a comment:


  • Walt Decker
    replied
    Thanks, Steve. That's different from what I learned years ago with other basics.

    Leave a comment:


  • Steve Rossell
    replied
    Originally posted by Walt Decker View Post
    I'm a little confused about what is going on with arrays.

    If I:

    DIM Array(20, 20)

    "Array" should be from 0 to 19, 0 to 19. Is that correct?

    However;
    Code:
    DIM Array(20, 20)
    
    FOR I = 0 TO 20
        FOR J = 0 TO 20
           Array(I, J) = 2
        NEXT J
    NEXT I
    I am actually doing each loop 21 times and no runtime error is generated. Why?
    No,
    Code:
    DIM Array(20,20)
    is the same as doing
    Code:
    DIM Array(0 to 20, 0 to 20)

    Leave a comment:


  • Walt Decker
    started a topic Arrays

    Arrays

    I'm a little confused about what is going on with arrays.

    If I:

    DIM Array(20, 20)

    "Array" should be from 0 to 19, 0 to 19. Is that correct?

    However;
    Code:
    DIM Array(20, 20)
    
    FOR I = 0 TO 20
        FOR J = 0 TO 20
           Array(I, J) = 2
        NEXT J
    NEXT I
    I am actually doing each loop 21 times and no runtime error is generated. Why?
Working...
X