Skip to content

Latest commit

 

History

History
45 lines (28 loc) · 1.69 KB

2.md

File metadata and controls

45 lines (28 loc) · 1.69 KB

LERN/LS/2

This example consists of a single file, LS/2.iss

Enter the command run lern/ls/2 to run the example.

This is a slightly less standard "Hello World!" example. It will still use the echo command to print "Hello World!" into the console, however this time it stores "Hello World!" in a variable.

Variables

A variable is used to keep some data. Different types of data can be stored by different variables, by specifying the type. Variables also need a name, and can optionally specify a default value.

Variables are defined with the variable keyword, like this:

variable string TextToDisplay="Hello World!"

or without a default value:

variable string TextToDisplay

In either case, a string variable by the name of TextToDisplay is created.

Reading variables

A Data Sequence is used to retrieve a value and emplace it in the command before execution.

A Data Sequence is denoted by ${ }, with an access sequence or name within it, like this: ${TextToDisplay}

Because the TextToDisplay variable contains the value Hello World!, the echo line will output exactly the same thing as LS/1.iss.

Any number of Data Sequences can be used in the same command, for example:

echo "${TextToDisplay} ${TextToDisplay} ${TextToDisplay}"

As you might imagine, this should output the value 3 times on the same line.

Exercises

  1. Change the name of the variable in each place it is used, and run the script again

  2. Add more uses of the variable in the same echo command, and run the script again

  3. Create your own .iss file with a main function, a string and your own echo command(s). Run it!