Arduino IDE: while Loop

Arduino IDE while Loop
About This Tutorial
This tutorial discusses what is a while loop, its general syntax in Arduino IDE, how it different from a for loop, and how it works.
Tutorial Info

Components Required

ImageComponentQuantityAvailable in Kit
evive1
USB A-B Cable1

Introduction

While loops execute a statement, or a group of statements continuously, and infinitely, until the expression inside the parenthesis, () results in false. Something must change the tested variable inside the body of while loop, or the control of the program will never exit the while loop. When you don’t know how many time the loop should execute, you should go for a while loop.

Structure

The following example shows the general while loop syntax in Arduino IDE. The control expression, i.e. the condition is written inside the parentheses. Unlike the for loop, the while loop has only one expression within its parentheses, and the looping behaviour depends on the activity inside the loop’s body.

while (condition) {
Body of while loop
}

Below is the flowchart showing how a while loop works:

Example

Arduino IDE for Loop

 

Share this Tutorial
Share on facebook
Facebook
Share on twitter
Twitter
Share on google
Google+
Share on pinterest
Pinterest
Share on reddit
Reddit
Share on print
Print
Related Projects & Tutorials
ldr circuit
How to interface LDR sensor with evive ?
The tutorial will shows how to interface ldr sensor with evive and controlling the led state using the sensor.How does ldr sensor works? How to control lights using ldr sensor? All the answers are given in this tutorial.Let's begin...
All articles loaded
No more articles to load
Featured Projects
DIY Mini Safe Locker Using Servo
DIY Mini Safe Locker Using Servo

Make your own DIY mini-safe locker using components from the evive Starter Kit and control it using evive’s slide switch!

All articles loaded
No more articles to load

Leave a Reply

Close Menu
×

Cart