Adobe PHOTOSHOP CS 2.0 - SCRIPTING GUIDE Manual page 31

Table of Contents

Advertisement

Adobe Photoshop CS2 Scripting Guide
AS
Set counter to 1
repeat with counter from 1 to 3
display dialog counter
end repeat
VBS
In VBScript, this type of loop is called a For-Next loop.
Dim counter As Integer
For counter = 1 to 3
Alert counter
Next
JS
In JavaScript, this type of loop is called a for loop.
Note:
In the following script, the variable that contains the counter is named i. This represents an
exception to the rule of thumb for good naming practices for variables. However, i is a traditional
counter variable name and most script writers recognize its meaning, especially when i is used in a
loop. See
var i
for (i =1; i < 4; i=i + 1)
{
alert(i)
}
The condition in the
i = 1
— If
i<4
don't do anything else with this loop.
i=i + 1
Note:
More Complex Loops
A more complicated type of loop includes conditional logic, so that it performs a task while or until some
condition is true. Conditional statements in a script can include the words while, until, or if — just like in
English.
For example, you could make the conditional statement "I'll use scripts only if they make my life easier. "
Another way to say this is, "I'll use scripts only on the condition that they make my life easier. "
Similarly, in the sentence, "I'll write scripts only while I'm at work, " the condition is being at work. The same
condition is worded with a slight difference in the following sentence: "I'll write scripts only until I leave
work. "
The following scripts use while loops to do the following:
1. Display a "Quit?" dialog.
The dialog contains two possible responses: an OK button and a Cancel button.
2. When the user clicks Cancel (for "Don't quit. " ), the script displays the dialog again.
'Naming Variables' on page 17
loop contains three statements (separated by semicolons):
for
— Set the value of
to 1.
i
is less than 4, execute the statement in brackets; if
i
— After executing the statement in the brackets, add 1 to the value of
The equation
i=i + 1
Photoshop CS2
for details on variable naming practices.
can be abbreviated to
is equal to or more than 4, stop and
i
.
i++
Scripting basics
27
.
i

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

Photoshop cs2

Table of Contents