Introduction

There are over 2.38 billion active Facebook users every month. Somehow, Facebook can send a โHappy Birthdayโ message to every single person that has Facebook. When you think about it, that is a remarkable feat!
Assuming an even distribution of Facebook users means that there are over 6,520,547 birthdays every day!
\(\frac{2380000\;users}{365\;days/year}=6520547.95\;birthdays/day\)
For the sake of argument letโs say that Facebook messages everyone saying โHappy Birthday! I just wanted to tell you Happy Birthday because I am a corporation that relies on you thinking of me as a human being!โ That is 26 words.
The world record for typing speed is 216 words per minute. It would take the fastest person in the world 0.12 minutes or 7.22 seconds to type that message. Not bad!
\(\frac{26\;words/message}{216\;words/minute}=0.12\;minutes/message*(60\;sec/min)=7.22\;sec\)
So if Facebook hired the fastest typist in the world, and locked them in a room and had them type that message to everyone in the world it would take them 544 days to write a short message to every person who had a birthday every day.
\(7.22\;sec/message*6520547\;messages=47078349\;seconds*(\frac{1\;hour}{3600\;seconds}=13077\;hours*(\frac{1\;day}{24\;hours})=544\;days\)
Clearly, this isnโt how Facebook does it. Not only is it extremely tedious, but it is also impossible. What they probably do, is have a single automated message and then loop through their database and send everybody that message who is having a birthday.
Whenever you run into a task that sounds tedious, it is likely a candidate for a computer! And you will probably need loops! So letโs learn about them.
Remember our mantra and guiding process for writing complex programs is: think, sketch, code, test, repeat.

In this chapter, we will learn how to program loops in MATLAB. That means learning:
-
What a MATLAB
forloop is and how it works. -
How to represent a
forloop in a flowchart. -
The only case when it is appropriate to use a
whileloop and why it is dangerous.
