Using Variables

 

Next Topic

 

The WIL Tutorial

§         Topic by Topic

§         The Tutorial Course

§         The Complete WIL Tutorial

 

Getting started

Using WIL

Reference

Notes

 

 

image\gflag6_shg.gif

 

 

A variable is simply a placeholder for a value. The value that the variable stands for can be either a text string (string variable) or a number (numeric variable). You may remember from Algebra 101 that if X=3, then X+X=6. X is simply a numeric variable, which stands here for the number 3. If we change the value of X to 4 (X=4), then the expression X+X is now equal to 8.

Okay. We know that the AskYesNo function returns a value of either @YES or @NO. What we need to do is create a variable to store the value that AskYesNo returns, so that we can use it later on in our WIL program. First, we need to give this variable a name. In WIL, variable names must begin with a letter, may contain any combination of letters or numbers, and may be from 1 to 30 characters long. So, let's use a variable called response. (We will distinguish variable names in this text by printing them in all lowercase letters; we will print function and command names starting with a capital letter. However, in WIL, the case is not significant, so you can use all lowercase, or all uppercase, or whatever combination you prefer.)

We assign the value returned by AskYesNo to the variable response, as follows:

 

response = AskYesNo("Really?", "Play Solitaire now?")

 

 

 

 

Tutor Example continued...

1. Exit Solitaire.

2. Edit tutor.wbt -Add variable name..

3. Save the file.

4. Run the wbt by double-clicking on the filename..

 

image\golftee_shg.gif Next…

 

Notice the syntax. The way that WIL processes this line is to first evaluate the result of the AskYesNo function. The function returns a value of either @YES or @NO. Then, WIL assigns this returned value to response. Therefore, response is now equal to either @YES or @NO, depending on what the user enters.

 

Now, we need a way to make a decision based upon this variable.