Re: 1 little sequence problem
=A9koda wrote:
> i get error message: variable s1 has not been assigned a value=20
true.
> subscript value 1 is out of bounds, assigning to a sequence of length =
0=20
think of the slice as trying to *replace* an existing item. so when you
write:
s1[1] =3D i
you say:
"replace the first item in the sequence s1 with i"
since there is no *first item* in s1 (it's empty, remember?), you get =
an
error.=20
these are logical errors of the same type. think of the sequence as an =
array
in this case - you can't ask for the nth item in the array if the array =
is
*smaller* than the index. in basic:
dim s1[0]
print s1[1] <-- error, the array has zero items in it.
when you wrote:
s1 =3D {}
you initialized the variable to an empty sequence - it still has no =
items in
it. so you can't ask for the nth item - there is no such animal. first
*fill* the sequence, and then replace the values, it will work:
sequence s1
' fill it with 10 zeros
s1 =3D repeat( 0, 10 )
for i =3D 1 to 10 do
' replace the i'th zero with i
s1[i] =3D i
end for
in this case:
s1 =3D repeat( 0, 10 )
is more or less akin to:
dim s1[10]
or you could build the sequence by appending value to the end of it:
sequence s1
' make it empty
s1 =3D {}
for i =3D 1 to 10 do
' append to the sequence
s1 =3D s1 & i
end for
or more succinctly, write:
s1 &=3D i
insead of:
s1 =3D s1 & i
Hope this helps!
-- David Cuny
|
Not Categorized, Please Help
|
|