### While Loop

There are other ways of harnessing the power of computers to complete repetitive tasks.

 ```while (ledPin>=9) {  pinMode (ledPin, OUTPUT);   digitalWrite (ledPin, HIGH);   delay(100);   digitalWrite (ledPin, LOW);   ledPin=ledPin-1; }```

This block of code sits in the void loop. It will be executed as long as the conditions in the parenthesis is true. As the program progresses and we get to the while we ask the question, "Is ledPin greater than or equal to 9?" If yes, then we do the code in the curly brackets. Then we ask the question again, if true we execute the code again. This keeps repeating until the answer is "no". Then the program continues on. Note, whatever variable is being checked must be changed within the while otherwise once the while loop starts it will never end.

 ```/* This code expands on the power of repetition by introducing while statements. You'll note there is no code in our setup process the pins are declared as needed in the loop. The circuit should have resistor-LEDs on pins 9-13. created 6 September 2010 by Steve Dickie electronics.arduinoeducation.com */ int ledPin = 13; void setup() { } void loop() {   while (ledPin>=9)             //Asks the question is ledPin >= 9 if true                                                                      //execute the code in the braces.  {    pinMode (ledPin, OUTPUT); //Set current pin to light-up as an output     digitalWrite (ledPin, HIGH); //Light up the current pin     delay(100); //Wait long enough for us to see it     digitalWrite (ledPin, LOW); //Turn the LED off     ledPin=ledPin-1;               //Advance to the next pin   }``` ```  ledPin = 13;           //Reset ledPin to start while over }```

This looks almost identical to the IF Loop we did in the last lesson. The "IF Loop" works as long as its the only thing you're doing in your void loop. However, what if you wanted to do something before or after you sequentially light your LEDs. In this case you could use a While statement. In fact you should be able to use this to make your LED sequencer go back and forth. This is not something you could do with your IF loop.

Comparison Operators:
As you might guess this involves comparing two values to each other. This might be useful when setting conditions for your while. Mostly this is straight forward but here it is anyway:

 x==y x is equal to y x!=y x is not equal to y x>y x is greater than y x>=y x is greater than or equal to y x

The operator that is most important to mention is "x is equal to y". The double equals sign is not a typo. A double equal sign is used to ask the question, does x equal y. If I used a single equals sign "x=y" I would be saying set the value of x to be the value of y. This difference is very important.