You are ready for a brand new topic in SoloLearn’s Introduction to Python course. Today’s post is the beginning of the third module in this course. The theme for this module is control flow.
The control flow module is made up of different very important programming concepts. I’ll be splitting them into multiple parts over the next few weeks, so you can go at your own pace. Some of the topics you’ll explore in this module are:
- control flow
- loops (for, while, and for each loops)
- conditional statements
I’m kicking off this new module by looking at control flow itself. Control flow is made up of many different factors. Developers need to pay attention to sequencing and iteration.
This post will review important techniques to keep in mind as you think of the flow of your program or game. These topics influence the control flow in each project you build. Next week, you will start diving deeper into some of these topics, starting with loops.
Sequencing
Sololearn defines sequencing as when computers run code from top to bottom. A key part of being a good web developer is being able to understand how computers run and work. Computers are powerful tools because they are great at following directions.
Sequencing is one of a computer’s great strengths, and knowing this will make it easier for you to communicate with it. It isn’t just important to Python. You can find sequencing in every programming language.
This means this is something you’ll encounter again and again in every programming language you learn. Order plays an important part in control flow, so pay close attention to how things are ordered in your code. Coding is a lot like baking because if one step is missed, it can create bigger problems in the future.
To have a good sequence in your program, you need to look at the code from the computer’s point of view and what it will do when it gets to each part of your code. Sequencing doesn’t help web apps and programs run efficiently. They help programs solve problems.
That is what makes them great tools that people will use every day. A lot of developers I admire and look up to are big believers in reading code. Reading through code will help you see how code is ordered and structured.
Look at the code of websites you like to visit or what others have written on GitHub. The goal here isn’t to understand every line of code. You want to look closely at the sequence being used in these programs and how it is structured in the code.
Iteration
Iteration means that code is being run multiple times. You can see iteration in real life. For example, putting a song on repeat is iteration.
Developers iterate their code using different kinds of loops. We will talk more about loops in next week’s post. Right now, you just need to know what iteration is because developers use this word often when they describe their code.
Selection
Control flow isn’t just about iteration and the sequence in your code. Selection is also something developers need to consider when creating control flow in their program. Selection is when developers let the computer know when to follow a specific path.
A real-life example of this in action is a smartwatch. One of my good friends wears a smartwatch to check her heart rate. When she was at a party and the room got very loud, her watch sent her a notification to let her know the room was too loud based on how her heart rate was going up.
Smart watches monitor heart rate and the steps you take, then make decisions based on that information. If someone’s heart rate moves out of a range like it did for my friend, the watch uses selection to notify you. When a computer reads code, it is making a decision.
There are a lot of decisions that computers need to make, so they need to combine sequencing, iteration, and selection to make these decisions. Without one of these three techniques, it will impact how quickly and efficiently a computer makes a decision. To better make good selections, three steps are used to help computers with the selection process.
1. Matching
Matching is the first step in this process. This means the computer completes tasks as long as it understands what it needs to do. People do this in real life by completing a task as long as they know how to do it.
To make sure the computer matches the right tasks it needs to complete the goals, it uses algorithms. Algorithms are sets of instructions that do a specific task in a certain order. Think of algorithms as the computer’s version of a recipe or an instruction manual. Algorithms are written in different ways and be used to do a variety of tasks so they can look a variety of ways.
Regardless of what algorithm is being used, the goal of every algorithm is to create a communication link between people and machines. Code is the bridge that allows developers and computers are able to talk to each other so certain tasks are completed. Matching helps machines reach their goals by making sure the instructions are written in a way it can understand, in the correct sequencing, and have no errors.
2. Pseudocode
Developers don’t dive straight into writing code once they are finished with matching. Many developers write pseudocode before they begin writing any code. Pseudocode is a simplified language that mirrors how a programming language acts.
Pseudocode can be used in every programming language and is popular among developers when they code because of how it mimics code. Writing pseudocode is similar to the rough draft process in writing or a rehearsal in theater. This is where a production or written work plans how everything will be before they create the final product.
Pseudocode functions like this code. Developers write what they want the program to do in a language they can understand. Then they translate this text into code a language computer can understand.
If you want examples of pseudocode in action, look at some of the Skillcrush 102 posts I’ve already written. The samples in these posts are how text is used to mirror JavaScript language. If you are getting started in coding, pseudocode is a technique you’ll want to use often because it mirrors the language you use.
3.Flow charts
Need a visual example of control flow? A great visual way of showing control flow in action are flow charts. Flow charts do a great job of showing the flow a program goes to do a specific task.
Skillcrush 102 used flow charts for a time in their class curriculum to show how the code would work in a program. Once students had some practice creating a flow chart and identifying the flow of how a program worked, they translated the flow chart into pseudocode and later code.
If you are stuck figuring out the flow of your program, don’t be afraid to use this technique to help you visually see how things are going to move. This is similar to storyboarding in writing. Sometimes writers need to create little images of how the story flows into one scene to get the flow just right before they actually create the scene.