4.2.1. Example 1: Using a for Loop

This example demonstrates using Power Syntax to wrap a for loop around some CCL Object definitions to repetitively change the visibility on the outer boundaries.

# Make the hub and shroud surfaces gradually transparent in
# the specified number of steps.
!$numsteps = 10;
!for ($i=0; $i < $numsteps; $i++) {
	! $trans = ($i+1)/$numsteps;
	GEOMETRY:
		HUB:
			Visibility = 1
			Transparency = $trans
		END
	END
	GEOMETRY:
		SHROUD:
			Visibility = 1
			Transparency = $trans
		END
	END
!}

The first line of Power Syntax defines a scalar variable called numsteps. Scalar variables (that is, simple single-valued variables) begin with a "$" symbol in Perl. The next line defines a for loop that increments the variable i up to numsteps. Next, we determine the fraction we are along in the loop and assign it to the variable trans. The object definitions then use trans to set their transparency and then repeat. Note how Perl variables can be directly embedded into the object definitions. The final line of Power Syntax (!}) closes the for loop.