Welcome to Coding with Carbs! This is where we try to break down daunting programming concepts into byte-sized digestible information that is relatable to the average joe! These comics provide a great way for you to teach coding concepts to kids as young as 6 years old.
What is Coding?
Coding or computer programming is the medium we use to communicate with computers. The code we write acts as a set of instructions that tells a computer what actions to take. Just like languages around the world, there are multiple programming languages to write the instructions in. Different grammar rules and "sentence structure" apply in different programming languages, however, the programming concepts and logic remain universal across the different languages. We will cover the most fundamental concepts that you'll learn in your first 10 hours of learning computer science.
Key Computer Science Coding Concepts
Similar to the variables often used in mathematics, they are containers for values that can change. You can think of them as buckets to put your coins in.
Variables = Buckets
Bucket A can contain 10 coins but if add 2 more it could contain 12, the number of coins inside Bucket A can vary.
2. Data Types
There are multiple types of items (data) you can store in the bucket (variable).
Alphabets, words, phrases, and punctuation can all form a string. String are usually denoted within the quotation marks "". Just imagine it as a chain of alphabets beads that are strung together to form your name.
They work exactly like how numbers should work.
An integer is a whole number, that can be positive or negative. They must not contain decimals.
Float is used to represents number with decimals.
Values that can be either true or false. They are usually used within a control flow's conditional parameters to determines the course of action.
Arrays are used to store multiple values in a single variable. As you can see, the drawer is the variable that is storing an array of numbers. The type of data (numbers/strings/float) drawer (variable) contains has to be the same.
3. Sequential logic
Actions occur one after the other, hence, the result from the previous action would potentially be required or affect the the outcome of the subsequent actions. The Contrast to it is the combinational logic.
A set of instructions to command a computing machine. An analogy would be a step by step recipe to cook a particular dish. You simply follow the instructions on the recipe to produce the desired dish.
5. For loops
Execute a set of actions/instructions an exact number of times. This is ideal for when you want to save time and let the computer run the same code over and over again without repeating it yourself.
An example would be running a 2.4km run on a standard stadium track.
Run 1 lap = Action that needs to be repeated
The same action that is repeated is 1 lap of 0.4km around the track.
Teacher = Coder
Instead of telling students to run 1 lap, run 1 lap, run 1 lap, run 1 lap, run 1 lap, run 1 lap, every time they pass the start line, the PE teacher could simply say, run around the track for 6 times.
Students = Computer
The students would repeat 1 lap around the track a total of six times before coming to a stop.
6. While loops
While loops are used when you want to repeat the actions while given conditions are true.
An example would be if you would like to find a particular book on a shelf that has multiple rows.
While book not found -> look for book
Book is not found = Condition given that is still True
Look for book = Action that is repeated
You will repeat the action of looking through the bookshelves row by row for the book because the condition is still true.
However, once you find the book, the given condition of book not found would end up being False, hence, you stop the action.
7. Nested Loops
Nested loops means that the instruction given within a loop is part of another loop.
Let's say you are a competitive eater and want to finish eating 20 boxes of cookies with each box containing 10 cookies.
You would first open up a bag, then consume all the 10 cookies, and repeat this with the other 19 boxes.
For 20 times, (Outer loop)
Open the box, (Instruction 1)
For 10 times, (Instruction 2) (Inner loop)
Eat 1 cookie
In this case, the first action would be to open up the box, then the second action is the nested inner loop where you consume 1 cookie for 10 times. Once 10 times is up, you will move on to the opening the next box.
The nested inner loop could also be written as a While loop.
For 20 times, (Outer loop)
Open the box, (Instruction 1)
While there is still cookie (Instruction 2) (Inner loop)
Eat 1 cookie
This would mean that within instruction 2, once there is no more cookie, the loop will stop and you will open the next box
8. If Else
A control flow that enables two choices based on a specified condition. An example would be lets say there are only two items on the menu for lunch, a sandwich which costs $5 and a burger which costs $3. You check your wallet for the amount of money you have, if the amount of cash you have is more than $3, you would go for the sandwich, otherwise you would settle for the burger instead..
9. Logic Operators - And/Or
They are used to evaluate 2 expressions as one. The resulting boolean value between the expressions changes according to the table shown below.
Looking at Expression 1 AND Expression 2 as one means that BOTH expression must be True in order for the boolean value to be resulted as True
Looking at Expression 1 OR Expression 2 as one means that just 1 of the 2 expressions need to be True in order for the boolean value to be resulted as True
Expression 1: 10 is bigger than 5 (Statement is True)
Expression 2: 3 is smaller than 1 (Statement is False)
In this case if we stating to check that Expression 1 AND 2 must be True, the resulting boolean will return a value of False because Expression 2 is a False statement.
If we are stating to check either Expression 1 OR 2 has to be True, the resulting boolean value will be True since Expression 1 is already True.
A control flow that enables multiple choices based on a specified condition. An alternative would be a sequence of repeating if-else. Let's say for example there are now more than two options on the menu and you are only looking to spend all your money on 1 item. There is sandwich that costs $5, a burger that costs $3, a chicken rice that costs $4, a hotdog that costs $2, and nuggets that costs $1. You check your wallet for the amount of cash you have and depending on the amount of cash you have, you would pick the respective meal.
A programming keyword that is used to force a loop to terminate/forcibly exit a loop. For example in a classic car race, the only way to terminate the laps early is when some parts of the car break. Only then will your car be able to leave the laps.
A signal sent to a processor that causes it to pause and figure out what to do next.
A Programming keyword that is used to call out an exception. Think of it as delegating the issue to someone else to handle or throwing your responsibilities to someone else to resolve.
A technical flaw in the program that results in the unexpected or unwanted results.
A form of exception/error handling. Programming code are first tested under the try clause, if there are errors, then the code under the catch clause will take effect. Let's imagine you are a secret agent and you want to escape through the window after you have gathered intel. You tried to open the window but it was sealed on tight, as a backup measure, you decided to escape through the air ventilation chamber instead.
A function is a block of code that only runs when it is called. You can pass data, known as parameters, into a function. A function can return data as a result.
A function that calls itself until its base case is met. An example would be lets say you want to display 6 dolls on a shelf and you are given a Russian doll with 5 other dolls within it. You would first open it one by one until you reach the smallest inner doll, then you place the smallest doll on the shelf and start to replace the lid of the second smallest doll and place that on the shelf. You then repeat it for the third smallest doll and so on and so forth. After repeating it for all the other dolls, you would eventually end up with 6 dolls on the shelf.
We hope you have enjoyed these byte-sized comics, they are also the perfect teaching resources for you teachers out there who want to use a fun way to introduce the concepts. Check out our free teaching and learning resources that put these concepts into practice on various programming languages such as Java, Python, and Swift and begin your computer programming journey.