website promotion banner
eturnkeys
Your Ad Here
Photoshop  Home Photoshop Miscellaneous Photoshop Scripting Basics: While Loops
rss

Photoshop Scripting Basics: While Loops

Author: FotoFects More by this author
Browse Pages: << <  1  2  3  4  5


While Loops

While loops are used to cycle through a series of instructions. It is similar to conditionals except it repeats the script until the while statement becomes untrue.

var i = 0 1. To create a loop, we need to create a number variable that will act like a counter; storing the number of times the loop has been run. We can use anything as the variable name but it is a programming tradition to use "i" as the counter variable. Using "i" as the variable will make it easier for other programmers to read your script. Set the value of the variable to 0.

var i=0
while () {
}
2. Now we can type in the while loop syntax.

var i=0
while (i<3) {
}
3. The condition we should put inside the while loop will be "i<3". This simply means that if the variable "i" (the variable that counts how many times the loop has be played) hasn't been played for 3 or more times, it will play the series of instructions it hold until it has been played 3 more more times.

var i=0
while (i<3) {
alert("The value of i is " + i);
}
4. We'll type in a simple alert script that displays the counter variable. Type in "alert("The value of i is " + i);".

var i=0
while (i<3) {
alert("The value of i is " + i);
i++;
}
5. After the script runs the alert function, it needs to tell the counter variable that it has been played once. To do this, we simply increase the "i" variable by 1 by typing in "i++".

image 5 6. Save your file as a *.jsx file on your desktop. You can name it whatever you want. Open Photoshop and run the file (File> Scripts> Browse). an alert dialog should popup three times.


print this page tell a friend subscribe to newsletter subscribe to rss
Rate this Material: Bad 1 2 3 4 5 Excellent
Browse Pages: << <  1  2  3  4  5

Add comments to "Photoshop Scripting Basics: While Loops"