definition of a variable code example

Example 1: what is a variable?

-- In programing variables exist in 99%(if not all) of programing languages:
-- Think of them as little boxes that can store data
-- some examples:

-- C#
  count = 0;
  While true
  {
    count = count + 1;
    print(count);
  }
  
-- Python
	count = 0
	While True:
    	count = count + 1
        print(count)
        
-- as you see, both of these programs will output:
1
2
3
4
5
6
7
8
9
...
-- and it will keep counting till you crash the program.

-- (ps I am using sql cause it looks nice and hilights a bunch of stuff)
-- Youtube: https://www.youtube.com/channel/UCBDHOr2HKOuMiWUj-Pu-AGA
-- Grep: https://www.codegrepper.com/app/profile.php?id=3325

Example 2: how to define variables

-Use pm.globals to define a global variable:

pm.globals.set("variable_key", "variable_value");

-Use pm.collectionVariables to
define a collection variable:

pm.collectionVariables.set("variable_key", "variable_value");

-Use pm.environment to define an environment
variable (in the currently selected environment):

pm.environment.set("variable_key", "variable_value");

-You can use unset to remove a variable:
pm.environment.unset("variable_key");

-Defining local variables
Local variables are temporary values you set
in your request scripts using the following syntax:

pm.variables.set("variable_key", "variable_value");

Tags:

Misc Example