Announcement

Collapse
No announcement yet.

FOR NEXT Wishes...

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

  • FOR NEXT Wishes...

    Hello

    I would like to see for next loops have there direction resolved automaticly. If the START is smaller then the END then increment the value but if the START is less than the END then decement the value.

    Code:
    for Index = 1 to 100
    next
    
    for Index = 100 to 1
    next

    Having to put "STEP -1" is obvious enough that you shouldn't have to put it there. I still think steps should be added but not indicate the sign. So to explain better, the for next loop should determine the sign of the step automaticly based on the START and END values and the step will always be a positive number indicating the stide of each loop.

    Code:
    for Index = 1 to 5 step .5
    next
    
    shows:
    1.0
    1.5
    2.0
    2.5
    3.0
    3.5
    4.0
    4.5
    5.0
    
    
    for Index = 5 to 1 step .5
    next 
    
    shows:
    5.0
    4.5
    4.0
    3.5
    3.0
    2.5
    2.0
    1.5
    1.0

    What do you guys think?



    ------------------
    Cheers

  • #2
    or
    For I = 5 DOWNTO 1
    Next
    ?


    ------------------
    -

    Comment


    • #3
      Mark --

      I don't know about anybody else, but that change would break a lot of my programs!

      Consider this example...

      Code:
      'Program displays "How many times do you want to BEEP?, allows
      'the user to enter a number from 0 to 10, and places the value
      'in the lBeepCount variable...
      '
      FOR lBeep = 1 TO lBeepCount
          BEEP
      NEXT
      The way FOR/NEXT works now, the program beeps the requested number of times. If the user enters zero, the program does not beep.

      With your change, it would beep twice.

      -- Eric


      ------------------
      Perfect Sync: Perfect Sync Development Tools
      Email: mailto:[email protected][email protected]</A>



      [This message has been edited by Eric Pearson (edited January 17, 2001).]
      "Not my circus, not my monkeys."

      Comment


      • #4
        Eric,

        I think to much time is spent on watching out for "Breaking code". How many times in the past have you had to change your code because there was a NEW feature implimented in PBDLL? At some point in time your code WILL break due to changes in the compiler. Change is an important thing, without it we just end up doing the same thing over and over and also harder. Look at all the changes that TurboBasic went through to become PBDOS35. I shudder to think of all the broken code in its wake. What are we gonna do with PBDLL when Microsoft totaly converts over to .NET are we still gonna sit here writing WIN32 code while the rest of the world races past us. On the other hand I do see your point and PowerBasic has doen a VERY good job at keeping code working throughout compiler releases.

        As for your example...
        Code:
        if (lBeepCount = 0) then...
        else
        end if
        Just my opinion really...




        ------------------
        Cheers

        Comment


        • #5
          Ummm, Mark?

          No!

          ------------------
          Tom Hanlin
          PowerBASIC Staff

          Comment


          • #6
            I don't think that this option is very high on many people's "Wish" list.
            However, if it was to be considered, I would go along with Wayne's idea
            of introducing the DOWNTO keyword, or perhaps re-using DESCEND as in
            "DESCEND TO" as an option.

            regards,

            ------------------
            [email protected]
            :) IRC :)

            Comment


            • #7
              I agree with Eric, it will break my code too.
              It's not just a matter of breaking code.
              If PB, for example, wanted to change the OPEN statement
              to OPENFILE, that's one thing because my code won't
              compile. It's a hassle, but it won't cause bugs. But
              changing the behavior of existing functions is a bad
              idea - it leads to bugs that are very, very hard to
              track down.

              my2cents,
              Don


              ------------------
              www.basicguru.com/dickinson
              Don Dickinson
              www.greatwebdivide.com

              Comment


              • #8
                Maybe it's just the way my own brain works (or fails to work) but if I can't remember to type STEP -1 I'm not going to remember to type DOWNTO either.

                What would you use as the equivalent for STEP -2? If DOWNTO means "DECR the counter instead of INCRing it" would you have to do...

                Code:
                FOR X = 10 DOWNTO 1 STEP 2
                ...or...

                Code:
                FOR X = 10 DOWNTO 1 STEP -2
                The first makes more sense to me, but then what would the second one do?

                Sorry, having two ways to specify the count direction is just too messy for my tastes...

                -- Eric


                ------------------
                Perfect Sync: Perfect Sync Development Tools
                Email: mailto:[email protected][email protected]</A>
                "Not my circus, not my monkeys."

                Comment


                • #9
                  Hey Tom,


                  Are you angry with me or something? Don't take what I say here as a slam about PowerBasic, I just wanted to know what people though. It seemed like a good idea before it was chewed up and spit out.


                  ------------------
                  Cheers

                  Comment


                  • #10
                    > It seemed like a good idea before it was chewed up and spit out.

                    I apologize if my responses were part of what made you feel that way. Sincerely!

                    I am 100% in favor of people posting ideas for PB features on this BBS! Some really good ideas have been posted in the past, and several of them have made it into the compiler. And even more probably will in the future, given PB's history of listening to its customers.

                    I'm also in favor of people pointing out potential benefits and potential problems with those suggestions. Negative comments are rarely intended as an attack against the suggestor... just people putting in their two cents about what is important to them.

                    Sometimes it's hard to convey "tone" in plain text...

                    -- Eric

                    ------------------
                    Perfect Sync: Perfect Sync Development Tools
                    Email: mailto:[email protected][email protected]</A>

                    [This message has been edited by Eric Pearson (edited January 17, 2001).]
                    "Not my circus, not my monkeys."

                    Comment


                    • #11
                      No problem!

                      I tend to have a strange sense of humor anyway! Maybe there is a way to convey mood in these forums other that with silly smiley faces. I still dont know how to use them(lazy). Anyway I thought the syntax for my suggestion just looked more readable but of course that's only MY personal feeling. Is there a way to change the color of your text in the forum? That way when the PB guys do get miffed with my question they can write back in RED. I always knew what the teachers RED pen ment


                      Thanks for all the reply's!!

                      ------------------
                      Cheers

                      Comment


                      • #12
                        Actually, I can think of a few instances where having a FOR/NEXT loop automatically calculate its STEP direction would be useful, such as when one or both of the start and end values depend on the result of a calculation...

                        However, I would definitely not advocate that it should become FOR/NEXT's default behavior!! Perhaps the FOR/NEXT syntax could be "enhanced" with an additional keyword that would specify the behavior, i.e.:

                        FOR var = start TO end STEP incr

                        would work (or fail to work ) as expected, while:

                        FOR var = start TO end AUTOSTEP incr

                        would automatically calculate whether incr needs to be positive or negative in order to satisfy the start and endpoints.

                        ------------------

                        Comment


                        • #13
                          Miffed, no. It's just that changing a fundamental building block
                          of the BASIC language in a way that would break 20 years of BASIC
                          code and confuse every existing BASIC programmer for no major value
                          is not a good prospect here... although it does seem to be a priority
                          with Microsoft right now, to which I can only say, "Go, lemmings! Go!"

                          Suggestions are always welcome. Some suggestions may be more
                          practical than others. Don't let that stop the brainstorms.


                          ------------------
                          Tom Hanlin
                          PowerBASIC Staff

                          Comment


                          • #14
                            I am much of the view that if you have something that works well, don't
                            mess it up. In PB, the FOR / NEXT loop is fast and well behaved so I
                            would loath to change it, especially as it works in much the same way
                            as traditional basic has for a long time.

                            Breaking code is a real problem, many people have code that has taken a
                            very long time to develop and to track down changes of this type in
                            existing code would be a major problem to many.

                            I think new ideas are worth the effort but they must be improvements,
                            not just changes and they should not be at the price of losing performance
                            or continuity in existing code.

                            Regards,

                            [email protected]

                            ------------------
                            hutch at movsd dot com
                            The MASM Forum

                            www.masm32.com

                            Comment

                            Working...
                            X