Looping: for ... in range

In the example below, the names of a scene's first 10 objects are being printed to RealFlow's "Messages" panel. There must be at least 10 objects, because otherwise you will get a syntax error!

The counter variable is constantly updated and used as an index to identify elements in the sceneAllObjects list:

# Mind the leading spaces, because otherwise you will get syntax errors!
sceneAllObjects = scene.getObjects()
numberOfObjects = 10
 
for counter in range(0, numberOfObjects):
	currentObject = sceneAllObjects[counter]
	nameObject    = currentObject.getName()
	scene.message(nameObject)

 

The next batch script adds all numbers from 0 to 100. The result variable will not be overwritten because of the += operator, but the new number will be added to the already existing result.

To get a correct output it is necessary to define the range from 0 to 101.

# Mind the leading spaces, because otherwise you will get syntax errors!
# Initialize the result variable
result = 0
 
for number in range(0,101):
	result += number
 
# Convert the number (integer) to a string
scene.message(str(result))