dimsyntax
dim ,
REMARKS: C style instantiations is a simpler alternative to using 'Dim'.

RELATED: global local static
 
'--------------
'DIM VARIATIONS
'==============

  '----------------
  'POST DEFINE TYPE
  '================
 
  dim i,j,k as long
  
  '---------------
  'PRE DEFINE TYPE
  '===============
  
  dim as long i,j,k
  
  '-----------
  'MIXED TYPES
  '===========


  dim as long i,j,k, as string s,t


  '----------
  'MULTI LINE
  '==========

  dim as long i,j,k,
      as string s,t


  dim as long,
  i,
  j,
  k

  '--------------
  'INITIAL VALUES
  '==============
  
  dim as long,
  i = 1,
  j = 2,
  k = 42
  
  '-------------------------
  'SPREAD LINES AND COMMENTS
  '=========================

  dim as long,
  
  i = 1,  ' these can be spread over many lines
  
  '--------
  j = 2,  ' with intervening comments
  
  '--------
  
  k = 42  '
  
  '--------------------
  'MULTIPLE ASSIGNMENTS
  '====================

  dim as long a(10) => (2,4,6,8,10,12,42,99)  
  print "Answer: "  str a(7)


  '-----------------
  'SYNTAX VARIATIONS
  '=================

  dim long a(10) => (2,4,6,8,10,12,42,99)  
  dim long a[10] => (2,4,6,8,10,12,42,99)  
  long a[10] => (2,4,6,8,10,12,42,99)  
  long a[10] <= (2,4,6,8,10,12,42,99)  
  long a[10] = {2,4,6,8,10,12,42,99}
  long a[] = {2,4,6,8,10,12,42,99}
  long a = {2,4,6,8,10,12,42,99}

  long a = 
  {
    2,4,6,8,10,12,42,99
  }


  '------------------
  'POINTERED VARIABLE
  '==================

  dim string s = "ABCDEFGHIJ"
  dim byte b at strptr s
  dim byte byref b : @b=strptr s
  byte b at strptr s
  byte *b = strptr s

  'print b[7] '71 G


  '--------------------
  'USING DYNAMIC MEMORY
  '====================

  dim float f at getmemory 1024*4 : f={1.5, 2.5, 3.5}
  'print f[2]
  freememory @f 'release allocated memory


  '---------------------------
  'DIMS: GLOBAL, STATIC, LOCAL
  '===========================

  global int g=1 'visible to rest of program following this statement

  function f(p as int) as int
    static int s=0 'permanent storage
    local int l=100 'temporary storage
    s+=10
    return p+l+s+g
  end function

  print f(1000) '1111
  print f(1000) '1121



  '--------------
  'LIMITING SCOPE
  '==============

  dim long a=16
  scope
    dim long a=1
    'print a '1
    ...
  end scope
  'print a '16