Photoshop CS2
Adobe Photoshop CS2 Scripting Guide
Scripting basics 27
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
‘Naming Variables’ on page 17
for details on variable naming practices.
var i
for (i =1; i < 4; i=i + 1)
{
alert(i)
}
The condition in the
for
loop contains three statements (separated by semicolons):
●
i = 1
— Set the value of
i
to 1.
●
i<4
— If
i
is less than 4, execute the statement in brackets; if
i
is equal to or more than 4, stop and
don’t do anything else with this loop.
●
i=i + 1
— After executing the statement in the brackets, add 1 to the value of
i
.
Note:
The equation
i=i + 1
can be abbreviated to
i++
.
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.
Содержание PHOTOSHOP CS 2.0 - SCRIPTING GUIDE
Страница 1: ...bbc Adobe Photoshop cs 2 Scripting Guide ...