Storing into Containers
The put
, set
, and get
commands are used to store values into containers. Several other commands will also change the value in a container.
put
, set
commands
The put ... into
command is used to assign a value to a container:
put 5 into count
put true into global peace
put customerName into word 2 of line 6 of customerStatement
The set
command can do the same thing:
set count = 5
set global peace to be true
set word 2 of line 6 of customerStatement to customerName
Syntax:
put source into container
set container [= | to {be {equal to}} | equal] source
Appending Values
The put
command (but not set
) can also append values at the beginning or end of a container, by specifying before
or after
instead of into
:
put "flower" into wordToMakePlural -- flower
put "s" after wordToMakePlural -- flowers
put heading & return before reportBody
put " " & customerLastName after word 2 of line 6 of customerStatement
put "$" before character firstDigit of Amount
Syntax:
put source [before | after] container
Storing Multiple Values At Once
Both the put
and set
commands can store values into several containers at once. To do this, list the containers separated by commas and enclosed in square brackets. If the source value is a single non-list value, that value will be assigned to all of the destination containers:
put zero into [a,b,c] -- sets a, b, and c all to zero
set [startTime, endTime] to "noon"
If the source value is a list, consecutive items from the source list will be assigned to each of the destination containers in turn. Excess values will be ignored:
put [1,2,3] into [a,b,c] -- sets a to 1, b to 2, and c to 3
set [x,y] to [y,x]-- swaps the values of x and y
Source values will be skipped if no container is provided to store them into:
put [1,2,3] into [a,,c] -- sets a to 1, and c to 3 (2 is ignored)