In any programming language, you will often need to make decisions. This will take the program into different functions depending on the answer of a question, result or evidence. This is called Control Flow and it is a collection of powerful instructions for decision making. Without them, electronic devices couldn't be able to make decisions upon evidence.
Table of Contents
What is Control Flow?
You might be asking yourself: what is the evidence? It is called binary values because they can only be either 1 or 0 and they are the result of a question, like:
- Is result A higher than result B?
- Is result B equal to 100?
- Is result A true?
If the answer is affirmative or 1, the code will execute a piece of code; if it is negative or 0, the code will execute another piece of code.
Types of Control Flow
There are different kinds of Control Flow instructions.
- one selection: if(if-else).
- multiple selection: switch.
- loops: while, do, for.
- jumps: break, continue.
I'm going to place here the Control Flow instructions in different sections as I compose them.
Examples of Control Flow
if
One of the most basic functions available is ‘if‘. A simple question where the answer is either true (1) or false (0); depending on the answer, a certain code will be executed. Click in the link below to read about it.
switch
For repetitive decision making, there is Switch. Excellent for programming and to leave the clutter behind. Click in the link below to read about it.
while
For repetitive tasks which require a sequence, ‘while‘ is frequently used. Click in the link below to read about it.
do
Coming soon!
for
Coming soon!
break
Coming soon!
continue
Coming soon!
techZorro's Index of Content
Keep Reading!
- Macros on C, how to create useful Aliases for the CodeMacros are tremendously helpful in saving time and clutter in code writing. This tutorial includes tutorials on C. Click here to read.
- Switch in C, the neat multiple decision maker in Control FlowIn Control Flow, Switch replaces multiples if's and merges into one elegant decision making solution. Click here to read.
- While loop in C language, the ‘ask first' of Control FlowWhile in C is great for creating loops using Control Flow. It's great for repeated tasks and counters! Click here to read more.
- Code Template, an easy guide for PIC Microcontrollers in CWriting a program with order is a time saver. Download today the code template for PIC microcontrollers for free. Click here to read more.
- Functions in C Programming LanguageFunctions lets you reutilize code efficiently and opens up libraries done by others. Click here to learn to use functions in C.
You have reached this far!
Thank you for reading the blog post. Your comments and suggestions are welcomed. At the bottom of this page, leave a message or just say hi! The whole team of techZorro will appreciate it. Don't forget to share it on social media as well.
techZorro’s Index of Content
Click on the following link to browse likewise content in the blog in techZorro. This index will help you see what you are looking for in a bird’s eye view.
techZorro's Newsletter!
If you enjoyed this blog post, please subscribe to techZorro’s newsletter so you don’t miss any future blog posts!
[…] it’s the best way to start with decision making, also known as Control Flow. Check out also this post about the other instructions for decision making in the C programming […]
[…] Control Flow in C language – if, while, for and many moreControl Flow introduces a series of instructions for deciding and controlling your code written in C. Click here to read. […]