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 |
2. Now we can type in the while loop syntax. | |
| |
||
var i=0 |
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 |
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 |
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++". | |
| |
||
![]() |
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. | |

10 Random Photoshop Miscellaneous :
10 Random TutorialKit Materials:







More Photoshop: