Vizard 8 » Tutorials & Examples » Python Programming » Looping logic
8.0

Looping logic

Now let's look at some examples of the basic logic used in Vizard scripts. Looping is a process by which a script loops through a set of statements repeatedly. The for statement is a particular kind of loop. It cycles through a list of variables or a range of numbers.

 

For example, let's say we wanted to make a sentence with each member of the array henhouse. We would use a for loop:

for bird in henhouse:
    print("A fox ate the", bird, ".")

Add this line to your script and run it. This statement repeats itself one time for every element in henhouse. Each time it does so, it sets the current element as the variable bird.  The for loop can also loop through every number in a range of numbers with the help of the range function:

for number in range(4):
    print("Close the barn door.")

Speaking Vizard's language

A quick note: Tips on scripts

Looping logic

If-then logic

Functions

An example