Wish Inline Dim

Discussion in 'Bugs & wishlist' started by Troberg, Mar 27, 2015.

  1. Troberg

    Troberg Well-Known Member Licensed User

    I very often find myself writing code such as:

    Code:
    Dim n as int
    For n=0 to 100
      
    'Do stuff
    Next
    Now, some languages have a neat construct which saves a mostly unnecessary line. In Basic, it would be something like:

    Code:
    For n as int=0 to 100
       
    'Do stuff
    Next
    Basically, an inline Dim where the variable is dimmed on first use. Somewhat like an even shorter form of:

    Code:
    Dim x as int = 0
    as a substitute for:

    Code:
    Dim x as int
    x=
    0
    Personally, I wouldn't use it on important or complex variables, but for trivial ones like in the example, it's very practical.
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    You don't need to call dim here at all.
    A for loop automatically declares an int value (if it is not already declared).
     
    Last edited: Mar 27, 2015
    Peter Simpson and Troberg like this.
  3. Troberg

    Troberg Well-Known Member Licensed User

    Nice, I did not know that!
     
  4. Jaames

    Jaames Active Member Licensed User

    And it is working like that from the first version I bought 1.8 (year 2012) :)
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice