Page 1 of 2 12 LastLast
Results 1 to 10 of 17

Thread: New in next thinBasic: FOR with on-the-fly variable definition

  1. #1
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10

    New in next thinBasic: FOR with on-the-fly variable definition

    In next thinBasic FOR clause will have a new syntax:
    [code=thinbasic]

    FOR Counter [AS AnyNumericType] = nStart TO nStop [STEP Increment] [{WHILE | UNTIL} LogicalExpression]
    ...
    NEXT

    [/code]

    So, it will be possible to define the looper controlling variable on the fly. Something like that will be valid:
    [code=thinbasic]
    for X as long = 1 to 16
    for Y as long = 1 to 16
    printat format$(x*y, "000"), X*4, Y, 14
    next
    next
    [/code]
    Before it was needed something like:
    [code=thinbasic]
    DIM X, Y AS LONG
    for X = 1 to 16
    for Y = 1 to 16
    printat format$(x*y, "000"), X*4, Y, 14
    next
    next
    [/code]

    Hope you like it.

    Ciao
    Eros
    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

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

    Re: New in next thinBasic: FOR with on-the-fly variable definition

    I will love it because playing with C++. I got used to doing this method.

    Thanks that is very nice surprise ERos!
    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

  3. #3

    Re: New in next thinBasic: FOR with on-the-fly variable definition

    Does the declared variable stay declared after the for loop is finished?

    Anyway, another nice addition to the language.

  4. #4
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10

    Re: New in next thinBasic: FOR with on-the-fly variable definition

    Quote Originally Posted by Michael Hartlef
    Does the declared variable stay declared after the for loop is finished?
    I too thought about that. Currently yes, it will remain declared.
    If you are in a GLOBAL scope (not inside any function), it will be declared GLOBAL. If you are inside a function, it will have LOCAL scope.
    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

    Re: New in next thinBasic: FOR with on-the-fly variable definition

    Dirty, C-ish, ... but I like it


    Thanks,
    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
    Join Date
    May 2007
    Location
    UK
    Posts
    1,427
    Rep Power
    159

    Re: New in next thinBasic: FOR with on-the-fly variable definition

    Is that optional or can we still use the old syntax?
    Home Desktop : Windows 7 - Intel Pentium (D) - 3.0 Ghz - 2GB - Geforce 6800GS
    Home Laptop : WinXP Pro SP3 - Intel Centrino Duo - 1.73 Ghz - 2 GB - Intel GMA 950
    Home Laptop : Windows 10 - Intel(R) Core(TM) i5-4210U CPU @ 1.70GHz, 2401 Mhz, 2 Core(s), 4 Logical Processor(s) - 4 GB - Intel HD 4400
    Work Desktop : Windows 10 - Intel I7 - 4 Ghz - 8GB - Quadro Fx 370

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

    Re: New in next thinBasic: FOR with on-the-fly variable definition

    As the datatype specification is in square brackets, I presume it means it is optional.
    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

  8. #8
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10

    Re: New in next thinBasic: FOR with on-the-fly variable definition

    Quote Originally Posted by Abraxas
    Is that optional or can we still use the old syntax?
    Of course optional. Standard FOR/NEXT will work as usual. It is just an additional way everyone can choose from.

    That's one of the advantages of an interpreted language: many syntaxes can be active at the same time and also it is quite easy to change and adapt.

    Eros
    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

  9. #9

    Re: New in next thinBasic: FOR with on-the-fly variable definition

    Hi guys interesting stuff but i prefer this:
    for X as long = 1 to 16
    for Y as long = 1 to 16
    printat format$(x*y, "000"), X*4, Y, 14
    next Y
    next X
    it is easy to track...

  10. #10
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10

    Re: New in next thinBasic: FOR with on-the-fly variable definition

    Well,

    thinBasic does not have NEXT followed by the controlling variable because it is not necessary. Every FOR/NEXT creates a nested level that the compiler or the interpreter are able to track by themself. But yes, adding the controlling variable after NEXT cen result is more readable code if you are used to that syntax.

    I'm sorry, I will not implement it for the moment because parsing the controlling variable after the NEXT takes a lot of time for the parser. But I will study if I can find a way to have both syntax with a minimum of speed loosing if variable is present.

    Ciao
    Eros
    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

Page 1 of 2 12 LastLast

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
  •