ANY-maze Help > The ANY-maze reference > The Protocol page > The elements of a protocol > Testing > Procedures > Elements of a procedure > Statements available to procedures > The Set value statement

The Set value statement

Introduction

The Set value statement is used to set the value of a user-defined variable. User-defined variables allow a procedure to keep an internal note of things that are important to a procedure - for example, a 'counter' to keep track of the number of times specific things happen.

The Set value statement has two parameters - the first of these is the variable whose value is being set, and the second is the new value to set the variable to. This new value can be a simple numeric, text, or True/False value, or could be the result of any operation that results in one of these values (for example, the result of a Maths function or operator, or the value of another variable).

Example

The following example procedure uses the Set value statement twice - firstly to initialise the value of a count to zero (which is done before the test starts), and then (within a loop) to increment a counter. Note that the value of the variable is set to the result of a mathematical function which adds 1 to the previous value of the variable.

  

  

Figure 1. A procedure showing the use of the Set value statement to initialise and then increment a variable used as a count.

Note that any variable can be set to a numerical, text, or True/False value (for the tech savvy, this means that variables do not have a 'type').

More information

A Set value statement can only be used to alter the value of a user-defined variable, and not a built-in variable. This is because built-in variables can only be read by a procedure, and not changed.

Shared variables

If a user-defined variable is defined to be shared between procedures, what happens if more than one procedure tries to change the value of the variable at the same time?

In fact, this can't happen, because of the way that procedures run - ANY-maze will look at each procedure in turn, and allow each one to run as much of the procedure as it can, until it either finishes running, or encounters a Wait until statement. It will then move on to the next procedure in the protocol.

Because of the way this works, only one procedure is running a statement at a time, so only one procedure can change the value of a variable at a time. However, it is quite possible that a procedure could change the value of a variable, only for another procedure to change it again almost immediately afterwards. For this reason, if you're writing multiple procedures for a protocol, you need to carefully consider how they will interact with each other.

See also:

 Statements available to procedures 
 The Wait until statement   
 The Action statement 
 The Repeat statement   
 The If statement     
 The Go to statement   
 The Label statement  
 The Run sub-procedure statement  
 The Note statement   
 Other statements 

© Copyright 2003-2026 Stoelting Co. All rights reserved

ANY-maze help topic T0482