Results 1 to 8 of 8

Thread: Suggestion: new for commands

  1. #1
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Naples, Florida & Duluth, Georgia
    Age
    67
    Posts
    3,869
    Rep Power
    404

    Suggestion: new FOR commands

    Easier to explain via an example. In C++ they do this:
    for ( int i = 0; i < limit; i++ )

    What is neat is that i is local for that loop. Right now we need to declare i outside of the loop as they do in C and it is not local

    The idea, 6 new commands:
    Fori, Forj, Fork, fFori , fForj, fFork each used with an optional stepType (boolean false or true) as following:

    optional stepType not used, steps in normal manner or as "false" was passed in.
    Fori 1, 10, 2

    In TB:
    long i
    for i = 1 to 10 step 2


    fFori 0.1, 0.9, 5, true

    in TB:
    single i
    for i = 0.1 to 0.9 step (0.9 - 0.1)/5
    Last edited by kryton9; 14-05-2017 at 21:46.
    Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
    Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server

  2. #2
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732
    Hi Kent,

    the idea with number of iterations instead of step for some cases is neat, the local variable as well!

    But I have to add few insights regarding the syntax.

    Functions with multiple parameters are confusing, especially those booleans. It is mentioned multiple times in Pragmatic Programmer and Code Complete - I would also vote to avoid such a designs, although I made similar mistakes in the past. Just have a look at TBGL_SetupLightSource... yikes!

    Also - while I am the last person to insist on inheriting legacy BASIC syntax, I like to keep "basic" as the design rule to lead us to the future.

    When you look at these:
    for i = 2 to 8 step 4
    
    print "Ciao" At 10, 5
    
    ... you are immediately oriented.

    When you see:
    fFori 0.1, 0.9, 5, true
    
    ... you need to think twice.

    So for the local variable, I would go this route:
    for single f = 1 to 10
    
    ...and for the implied number of iterations:
    for f = 1 to 10 in 5 steps
    
    (for example)

    -

    Do you remember? ThinBASIC had this implemented, not sure where it got lost (Eros?):
    for i as long = 1 to 10
    next
    
    for i = 2 to 8
    next
    
    So... you see, the i gets declared as part of first cycle and can be recycled in second.

    Advantages?

    No variable deallocation at end of each cycle brings more performance.


    Petr
    Last edited by Petr Schreiber; 15-05-2017 at 10:23.
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  3. #3
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Naples, Florida & Duluth, Georgia
    Age
    67
    Posts
    3,869
    Rep Power
    404
    You make good points Petr for BASIC like syntax.

    I don't remember the older thinBasic for's that you wrote about, no surprise there with my bad memory

    I am in favor of your suggestions if possible:

    for i = 2 to 8 step 4
    
    for single f = 1 to 10
    
    for f = 1 to 10 in 5 steps
    
    Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
    Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server

  4. #4
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10
    Ciao Petr, what do you mean with "lost" ?
    Quote Originally Posted by Petr Schreiber View Post
    Do you remember? ThinBASIC had this implemented, not sure where it got lost (Eros?):
    http://www.thinbasic.com/public/prod...ml?fornext.htm

    Loop variable supporting FOR/NEXT can be declared on the fly but it is not removed afterwards due to time it takes to de-allocate it.

    Personally I'm with Petr when he says we need to remain with BASIC syntax as much as possible even if I like to add some "contamination" if they are useful to the programmer and bring some execution advantages/speed.
    I hate short variable declaration, I like long names for variables
    I like code to be able to be read after many years without double concentration to follow variable meaning.
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  5. #5
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732
    Hi Eros,

    I am sorry for confusion - I checked and it works in the latest thinBASIC indeed.
    I remember I tried to use it at work and it caused runtime error, but I probably run into some issue not present now.


    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  6. #6
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Naples, Florida & Duluth, Georgia
    Age
    67
    Posts
    3,869
    Rep Power
    404
    I get an error here guys.
    ErrorFor.png
    TBInfo.png
    Last edited by kryton9; 16-05-2017 at 19:13.
    Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
    Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server

  7. #7
    You forgot to declare the variable.

    This works

    Uses "console"
    
    For i As Long = 1 To 10
    
    
      PrintL Str$(i)
      
    Next
    

  8. #8
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Naples, Florida & Duluth, Georgia
    Age
    67
    Posts
    3,869
    Rep Power
    404
    Thanks Mike! User error strikes again
    I got too used to brevity the last few years.
    Last edited by kryton9; 16-05-2017 at 19:19.
    Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
    Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server

Similar Threads

  1. Experimental commands: GRAPHIC
    By ErosOlmi in forum thinBasic vaporware
    Replies: 3
    Last Post: 12-12-2007, 00:14

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •