While Loop
 

Step 1 - Build the Project

The "while" loop iterates ,or counts through, one or more commands. The loop will repeat until a condition is met that makes it break; it runs until something stops it from running.

Note: If you're uploading this project directly from the website, first click Run on Arduino, complete the upload, then scroll down and click the Connect button in the Serial Monitor. This allows the data to be sent from the Maker Board to the Serial Monitor.

Step 2 - Upload the Code

/* * Learning examples: While * * Print count while less than 10 */ void setup() { Serial.begin(9600); byte i= 0; while (i < 10){ //While i is less than 10 Serial.println(i); //Print i delay(100); //Wait for visibility i++; //And increment i } } void loop() {//nothing in the loop! } // (c) 2016 Let's Start Coding. License: www.letsstartcoding.com/bsdlicense
 

Step 3 - Read the Walkthrough

A “while” loop iterates until the condition between the parentheses is false.

This statement is most useful when you're not sure what values will be in the condition. You can create a “while” loop to run forever if you want.

In this code, the byte variable is declared with a value of 0, so the "while" loop will count up to 10 from 0. If the value of i started as 5, the "while" loop would run up to 10 from 5. 

Now no matter what the value of i was when the “while” loop started, it will increase by one each time the “while” loop runs until i isn't less than 10.