Data analysis 2 (Basic loop)

Click to compare with Python equivalents

Macros

command [action]
2.1. local macro-name value [ stores value under macro-name ]
2.2. sleep milliseconds [ wait milliseconds before executing next command ]
2.3. while expression [ executes command if expression is true]
2.4. forvalues macro-name = range [ executes command if value of macro is in range ]
2.5. foreach macro-name = list [ executes command for each element of macro ]
command [action]
2.1. import [ imports a module ]
2.2. sleep() [ wait seconds before executing next command ]
2.3. while [ A while loop will continue until the statement is false ]
2.4. for [ can be used to iterate through a sequence ]
2.5. range() [returns a sequence of numbers, starting from 0 by default, and increments by 1 (by default), and stops before a specified number.

Make a local macro using a string (words):

    local name "John"

Make a local macro using a string (words):

    name="John"

Print local macro "name":

    display "`name'"

Print local macro "name":

    print(name)

Make a local macro using numbers:

    local age = 31

Make a local macro using numbers:

    age=31

Print local macro age:

    display `age'

Print local macro age:

    print(age)

Print both local macros:

    display "`name' is `age' years old"

Print both local macros:

    print(name, "is", age, "years old")

Load Time Module

    from time import sleep

Basic loop using while true

    local i = 1

counter set to 1

    while `i'< 10 {
    display "hello world `i'"
    local i = `i'+ 1
    sleep 1000
    }

Basic loop using while true

i=1

counter set to 1

while i < 11:
    print("hello world", i)
    i += 1
    sleep(1)

Basic loop using forvalues

    forvalues i = 1/10 {
    display "hello world `i'"
    sleep 1000
    }

Basic loop using for

for i in range(10):
    print("hello world", i)
    sleep(1)

Counting by 2:

    forvalues i = 1(2)10 {
    display "hello world `i'"
    sleep 1000
    }

Counting by 2:

for i in range(1, 12, 2):
    print("hello world", i)
    sleep(1)

Basic loop over list

Create list of juice

    local juice "apple orange grape"

loop over each element of list "juice"

    foreach i in `juice' {
    display "`i' juice"
    sleep 1000
    }

Basic loop over list

Create list of juice

juice = ["apple", "orange", "grape"]

loop over each element of list "juice"

for i in juice:
    print(i, "juice")
    sleep(1)