LET Statement |
LET var-name = value LET array-name[(subscript)] = value LET array-name[(subscript)] = array-name[(subscript)]
Assign a variable a value. LET can be omitted. The latest version of MyBASIC2 allows arrays with or without subscripts to be assigned a value or another array of the same size. In this case, size is the number of array elements an array can hold. For example, an array(3,3) has the same size as array(9) and you can make such an assignment. This can be useful in case you need to convert array dimensions.
When assigning a value to an array, you can omit subscripts from right to left. This is the same as replacing any subscripts omitted with the wild card character '*'. For example;
DIM array( 4, 3 ) AS REAL LET array( 1 ) = 1 ' Is the same as... LET array( 1, * ) = 1
Strong vs Weak Variable Typing
When using DIM to declare variables with OPTION EXPLICIT ON the typing is assumed to be strong and there are some limitations on how you can assign from one variable type to another. Main difference being that when strong is on, you can't assign a REAL to an INTEGER. See table below.
Examples:
' Basic value assignments LET a = 1 b = 2 str = "Kalle Anka"
' Array examples DIM nisse(2,3) AS INTEGER DIM kalle(2,3) AS INTEGER
' Basic Array Assignments LET nisse(1,1) = 8 LET nisse(1,2) = 8 LET nisse(1,3) = 8
' Initialize an array or part of an array LET nisse = 1 LET nisse(*) = 1 LET nisse(*,1) = 1 LET nisse(*,2) = 2 LET nisse(*,3) = 3 LET nisse(2,*) = 2
' Copy one array to another or part of array LET kalle = nisse LET kalle(1,*) = nisse(1,*)
' Examples showing "slicing" one array ' into another using "Wild" indexes DIM Arr(10,4,3) AS REAL DIM Slice(10,2) AS REAL DIM Vector(10,3) AS REAL DIM One(10) AS REAL
LET Slice(*,1) = Arr(*,1,1) LET One = Arr(*,4,1)
LET Vector(*,1) = Arr(*,2,1) LET Vector(*,*) = Arr(*,2,*) LET Vector = Arr(*,2) LET Arr(*,2) = Vector LET Arr(*,2,*) = Vector(*,*)
|