Incrementing a value

Tcl provides a simple method for incrementing a value stored within a dictionary with the dict incr command. This is extremely useful when storing numeric values in the dictionary. The syntax is as follows:

	dict incr dictionaryValue key increment

How to do it…

In the following example, we will create a dictionary containing a key/value pair and then using the dict incr command, we will increase the value associated with the key specified. Return values from the commands are provided for clarity. Enter the following command:


% set numbers [dict create one 1]
one 1
% dict incr $numbers one 3
one 4

How it works…

The dict incr command will increase the value stored in key by the amount defined within the increment parenthesis for the dictionary referenced by dictionaryValue.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.58.120.57