[ic] [*-increment]

Mark Johnson interchange-users@lists.akopia.com
Thu Jul 5 08:43:01 2001


Tim Mirecki wrote:
> 
> Why not create a scratch variable? Like this:
> 
> [seti counter]0[/seti]
> 
> [loop]
> 
>   *** your loop code ***
>   [seti counter][calc interpolate="1"][scratch counter]+1[/calc][/seti]
> 
> [/loop]
> 
> That way you can set what number is starts at, add a number each time,
> subtract a number...or five if you want. Much better than complicating an
> Interchange tag with more properties.
> 
> ciao

This is certainly true, but there are also efficiency issues to
consider. As a compromise, consider using the list calc.

[set my_increment][/set]
[loop]
...
[loop-calc] $Scratch->{my_increment} = $start_val       # if you want a
non-zero start
		unless $Scratch->{my_increment} ||      #
		       $Scratch->{my_increment} eq '0'; #
	$Scratch->{my_increment} += $adj_value; # Of course, this can be as
complicated as you need.
	return $Scratch->{my_increment};[/loop-calc]
...
[/loop]

Just be aware that using the list calc option, your scratch value will
not be available on a per-block basis. So, if you use the above code,
but then added a [scratch my_increment] anywhere in the list block, that
value will interpolate uniformly to the last value set in the loop. If
you want the [scratch my_incrememt] to interpolate for each block
preserving the value of that iteration, you will have to use the
less-efficient [calc] in place of [loop-calc].

-- 
Mark Johnson
Senior Systems Architect - Professional Services
Red Hat, Inc.
E-Business Solutions
markj@redhat.com
703-456-2912