Computer Science: Sequences, Selections, and Loops

Lesson 5: Sequences, Selections, and Loops


Sequences, selections, and loops

Behind all of the software we use on a daily basis, there's a code being run with all sorts of terms and symbols. Surprisingly, it can often be broken down into three simple programming structures called sequences, selections, and loops. These come together to form the most basic instructions and algorithms for all types of software.

Watch the video below to learn more about sequences, selections, and loops.

A sequence is a series of actions that is completed in a specific order. Action 1 is performed, then Action 2, then Action 3, etc., until all of the actions in the sequence have been carried out.

A sequence we do every day is a morning routine. You might wake up, drink some water, take a shower, eat breakfast, and so on. Everyone's routine is different, but they're all made up of a sequence of various actions.

Selections are a bit different. Instead of following a specific order of events, they ask a question in order to figure out which path to take next.  

Let's say you go to brush your teeth, and you find that you're out of toothpaste. You'd then ask, "Do I have any more toothpaste?" If the answer is no, then you would add it to your shopping list. But if the answer is yes, you would just use the toothpaste. This is really all a selection is doing: answering a question based on what it finds.

The third programming structure is a loop. Like selections, loops ask questions. However, the difference is that they ask the same question over and over and over again, until a certain task is complete.

For example, take the act of hammering a nail. Even though you may not realize it, you're constantly asking yourself, "Is the nail all the way in?" When the answer is no, you hammer the nail again. You continue to repeat this question until the answer is yes, and then you stop. Loops allow programmers to efficiently code repetitive tasks instead of having to write the same actions over and over again.

These three programming structures may seem pretty simple on their own, but when combined they can create some pretty complex software.