Build Your Own AI Assistant Part 1 - Creating the Assistant
116820 Views
Is the new Raspberry Pi AI Kit better than Google Coral?
114678 Views
Control Arduino with Python using Firmata / PyFirmata
87081 Views
How to Map with LiDAR - using a Raspberry Pi Zero 2W, RPLidar and Rviz
57314 Views
Creating a Supercomputer with a Raspberry Pi 5 Cluster and Docker Swarm!
53588 Views
Node-Red Automation, MQTT, NodeMCU & MicroPython
52067 Views
LEGO Gets Lights & Sound with Tiny FX
Thinkman
Podman vs Docker
MicroPython Robotics
Bottango and Isaaca
LidarBot
Getting Started with C on the Raspberry Pi Pico
0h 20m
Running K3s on Raspberry Pi
0h 36m
From Docker to Podman
0h 28m
MicroPython Robotics Projects with the Raspberry Pi Pico
0h 24m
Bottango Basics
0h 22m
Mini-Rack 3D Design Tutorial
Learn how to Program in Python, C, Rust, and more.
Learn Linux from the basics to advanced topics.
Learn how to use a Raspberry Pi Pico
Learn MicroPython the best language for MicroControllers
Learn Docker, the leading containerization platform. Docker is used to build, ship, and run applications in a consistent and reliable manner, making it a popular choice for DevOps and cloud-native development.
Learn how to build SMARS robots, starting with the 3D Printing the model, Designing SMARS and Programming SMARS
Learn how to build robots, starting with the basics, then move on to learning Python and MicroPython for microcontrollers, finally learn how to make things with Fusion 360.
Learn Python, the most popular programming language in the world. Python is used in many different areas, including Web Development, Data Science, Machine Learning, Robotics and more.
Learn how to create robots in 3D, using Fusion 360 and FreeCAD. The models can be printed out using a 3d printer and then assembled into a physical robot.
Learn how to create Databases in Python, with SQLite3 and Redis.
KevsRobots Learning Platform
40% Percent Complete
By Kevin McAleer, 3 Minutes
Page last updated June 15, 2025
Now that you can store data with variables, letβs add logic to your programs with conditionals and loops.
This lesson will teach your programs how to make decisions and do things over and over again β two key skills for any kind of automation or embedded programming.
Use if to check if something is true, and act accordingly.
if
#include <stdio.h> int main() { int temperature = 30; // Set the variable temperature to 30 if (temperature > 25) { // Check if temperature is greater than 25 printf("It's hot today!\n"); } else { // If not, do this printf("It's not too hot.\n"); } return 0; // End the program }
You can also use else if:
else if
if (temp > 25) { // ... } else if (temp > 15) { // ... } else { // ... }
==
a == b
!=
a != b
>
a > b
<
a < b
>=
a >= b
<=
a <= b
Loops let you repeat something multiple times β great for blinking LEDs, checking sensors, or running forever.
while
int count = 0; while (count < 5) { // Repeat the code block while count is less than 5 printf("Count: %d\n", count); count++; // Increment count by 1 }
This will print Count: 0 through Count: 4.
Count: 0
Count: 4
for
A for loop is a shorter way to repeat something a specific number of times. for loops require three parts:
int i = 0;
i
i < 5;
i++
for (int i = 0; i < 5; i++) { printf("i = %d\n", i); }
This does the same thing as the while loop above β itβs just shorter.
Microcontrollers often run in an infinite loop, doing tasks over and over:
while (1) { // Do something forever }
Weβll use this when we get to controlling the LED!
You now know how to:
else
Next up: Functions in C, where weβll start breaking our programs into reusable chunks!
< Previous Next >
You can use the arrows β β on your keyboard to navigate between lessons.
β β