|
|
(7 intermediate revisions by 3 users not shown) |
Line 1: |
Line 1: |
| '''Statement''' | | Erase ''arrays'' |
|
| |
|
| ERASE ''arrays''
| | == Description == |
|
| |
|
| '''Description''' | | Erase reinitializes fixed-size arrays, and releases memory allocated for dynamic-array storage. The required component, ''arrays'', is a comma separated list of one or more (up to 7) array variables. |
|
| |
|
| ERASE reinitializes fixed-size arrays, and releases memory allocated for dynamic-array storage. The required component, ''arrays'', is a comma separated list of one or more array variables.
| | A faster way to do this is to simply force the recreation of the array: |
| | <pre> |
| | myArray = [] |
| | </pre> |
|
| |
|
| '''Example'''
| | == Example == |
|
| |
|
| <pre> | | <tabber> |
| REM ERASE Example
| | JavaScript= |
| 'ERASE reinitializes arrays | | <syntaxhighlight lang="JavaScript"> |
| DIM Children(3)
| | // Erase Example |
| | /* Erase reinitializes arrays */ |
| | |
| | Erase = function(arr) { |
| | var i; |
| | for (i=0; i<arr.length; ++i) { |
| | arr[i]=''; |
| | } |
| | } |
| | |
| | PrintArray = function(arr, elements) { |
| | var i; |
| | for (i=0; i<elements; ++i) { |
| | NSB.Print("#" + i + ": (" + arr[i] + ")"); |
| | } |
| | NSB.Print(); |
| | } |
| | |
| | var Children=new Array(3); |
| | Children[0] = "Eric"; |
| | Children[1] = "Kenny"; |
| | Children[2] = "Kyle"; |
| | Children[3] = "Stan"; |
| | PrintArray(Children, 4); |
| | Erase(Children); |
| | PrintArray(Children, 4); |
| | </syntaxhighlight> |
| | |-| |
| | BASIC= |
| | <syntaxhighlight lang="vb.net"> |
| | Rem Erase Example |
| | 'Erase reinitializes arrays |
| | Dim Children(3) |
| Children(0) = "Eric" | | Children(0) = "Eric" |
| Children(1) = "Kenny" | | Children(1) = "Kenny" |
Line 18: |
Line 53: |
| Children(3) = "Stan" | | Children(3) = "Stan" |
| PrintArray Children, 4 | | PrintArray Children, 4 |
| ERASE Children
| | Erase Children |
| PrintArray Children, 4 | | PrintArray Children, 4 |
| FUNCTION PrintArray(arr, elements)
| | Function PrintArray(arr, elements) |
| DIM i | | Dim i |
| FOR i = 1 to elements | | For i = 1 to elements |
| PRINT "#" & i&":","("&arr(i-1)&")" | | Print "#" & i&":","("&arr(i-1)&")" |
| NEXT | | Next |
| PRINT | | PRINT |
| END FUNCTION
| | End Function |
| </pre> | | </syntaxhighlight> |
| | </tabber> |
|
| |
|
| '''Output'''
| | == Output == |
|
| |
|
| <pre> | | <pre> |
Line 42: |
Line 78: |
| </pre> | | </pre> |
|
| |
|
| '''Related Items'''
| | == Related Items == |
| | |
| | [[array|Array]], [[dim|Dim]] |
| | |
| | [[Category:Language Reference]] |
|
| |
|
| [[array|ARRAY]], [[dim|DIM]] | | [[Category:Variables]] |
Erase arrays
Description
Erase reinitializes fixed-size arrays, and releases memory allocated for dynamic-array storage. The required component, arrays, is a comma separated list of one or more (up to 7) array variables.
A faster way to do this is to simply force the recreation of the array:
myArray = []
Example
// Erase Example
/* Erase reinitializes arrays */
Erase = function(arr) {
var i;
for (i=0; i<arr.length; ++i) {
arr[i]='';
}
}
PrintArray = function(arr, elements) {
var i;
for (i=0; i<elements; ++i) {
NSB.Print("#" + i + ": (" + arr[i] + ")");
}
NSB.Print();
}
var Children=new Array(3);
Children[0] = "Eric";
Children[1] = "Kenny";
Children[2] = "Kyle";
Children[3] = "Stan";
PrintArray(Children, 4);
Erase(Children);
PrintArray(Children, 4);
Rem Erase Example
'Erase reinitializes arrays
Dim Children(3)
Children(0) = "Eric"
Children(1) = "Kenny"
Children(2) = "Kyle"
Children(3) = "Stan"
PrintArray Children, 4
Erase Children
PrintArray Children, 4
Function PrintArray(arr, elements)
Dim i
For i = 1 to elements
Print "#" & i&":","("&arr(i-1)&")"
Next
PRINT
End Function
Output
#1: (Eric)
#2: (Kenny)
#3: (Kyle)
#4: (Stan)
#1: ()
#2: ()
#3: ()
#4: ()
Related Items
Array, Dim