Swipe

Swipe

SwipeSwipe

Paths

Motivation

Information

←Back to Coding
Coding Β· Learning Area

Core Programming Concepts

Master the fundamental building blocks of programming. Learn how variables, conditions, loops, functions and other core concepts work together to create software in any programming language.

Core Programming Concepts preview

Introduction

Variables are one of the first concepts every programmer learns. A variable is a named container that stores information so it can be used throughout a program. Instead of repeating the same value multiple times, you store it in a variable and reference it whenever you need it.

Variables can hold many different types of data, including text, numbers and true or false values. Every applicationβ€”from websites and mobile apps to games and AI systemsβ€”uses variables to manage information.

Why It Matters

Without variables, programs couldn't remember information or respond to user input. Imagine an online store that couldn't remember a customer's name, the price of a product or the contents of a shopping cart. Variables make software dynamic by allowing information to be stored, updated and processed.

Key Principles

What is a Variable?

A variable has three parts:

  • Data Type (in some languages optional)
  • Variable Name
  • Value

Think of a variable as a labeled box that stores information: Data Type + Variable Name = Value, or simply Variable Name = Value, depending on the programming language.

Common Data Types

String β€” stores text.

Examples: "Hello", "Swipe", "John Smith"

Number β€” stores numeric values.

Examples: 25, 3.14, 2026

Boolean β€” stores only two possible values: true or false.

Booleans are commonly used for questions such as:

  • Is the user logged in?
  • Has the payment been completed?
  • Is dark mode enabled?
Variable Syntax in Popular Languages

Although the syntax looks different, every language below is creating a variable called name that stores the text "John".

  • Python β€” name = "John"
  • JavaScript β€” let name = "John";
  • TypeScript β€” let name: string = "John";
  • Java β€” String name = "John";
  • C# β€” string name = "John";
  • C++ β€” string name = "John";
  • Go β€” name := "John"
  • Rust β€” let name = "John";

Examples

Variables are used everywhere:

  • Storing a user's name.
  • Tracking a game score.
  • Saving a product price.
  • Remembering login status.
  • Calculating a shopping cart total.

Common Mistakes

  • Choosing unclear variable names.
  • Mixing different data types.
  • Creating unnecessary variables.
  • Forgetting that variables can change over time.

Exercises

  • Create one String, one Number and one Boolean variable.
  • Write the same variable in two different programming languages.
  • Think of five real-world examples where variables are used.

Summary

Variables are one of the most important building blocks of programming. They allow programs to store, update and manage information efficiently. Although every programming language has its own syntax, the idea behind variables is always the same: giving a piece of data a name so it can be used throughout a program.

Introduction

Variables store information, but not all information is the same. A person's name is text, their age is a number, and whether they are logged in is either true or false. These different categories of information are called data types.

Data types help programming languages understand what kind of data is being stored and what operations can be performed on it. Choosing the correct data type makes programs more reliable, efficient and easier to understand.

Why It Matters

Every program works with data. Whether you're building a website, a mobile app or a game, you'll constantly store, process and display information. Understanding data types helps you avoid errors and write cleaner, more predictable code.

Key Principles

String

A String stores text.

Examples: "Hello", "Swipe", "John Smith"

Number

A Number stores numeric values.

Examples: 25, 3.14, 2026

Numbers are used for calculations such as prices, scores and measurements.

Boolean

A Boolean stores only one of two values: true or false.

Booleans answer simple yes-or-no questions, such as:

  • Is the user logged in?
  • Is dark mode enabled?
  • Has the payment been completed?
Array

An Array stores multiple values in a single variable.

Example: ["Apple", "Banana", "Orange"]

Arrays are useful for lists of items.

Object

An Object stores related pieces of information together.

Example: name: "John", age: 24, isStudent: true

Objects describe real-world things with multiple properties.

Data Types Across Popular Languages

Every programming language supports the same core data types, even though the syntax may be slightly different.

  • Python β€” name = "John" Β· age = 24 Β· isStudent = True
  • JavaScript β€” let name = "John"; Β· let age = 24; Β· let isStudent = true;
  • TypeScript β€” let name: string = "John"; Β· let age: number = 24; Β· let isStudent: boolean = true;
  • Java β€” String name = "John"; Β· int age = 24; Β· boolean isStudent = true;
  • C# β€” string name = "John"; Β· int age = 24; Β· bool isStudent = true;
  • C++ β€” string name = "John"; Β· int age = 24; Β· bool isStudent = true;
  • Go β€” name := "John" Β· age := 24 Β· isStudent := true
  • Rust β€” let name = "John"; Β· let age = 24; Β· let is_student = true;

Examples

Data types are used everywhere:

  • A username is stored as a String.
  • A product price is stored as a Number.
  • A login status is stored as a Boolean.
  • A shopping cart stores products in an Array.
  • A user profile is represented as an Object.

Common Mistakes

  • Using the wrong data type.
  • Treating numbers as text.
  • Forgetting that Booleans only have two values.
  • Choosing an Array when an Object would be more appropriate.

Exercises

  • Write one example of each data type.
  • Create an Array containing your three favorite foods.
  • Describe yourself using an Object with at least four properties.
  • Think of three real-world examples where each data type could be used.

Summary

Data types define the kind of information a variable stores. The most common types include Strings, Numbers, Booleans, Arrays and Objects. Understanding when to use each one is an essential skill that will help you write cleaner, safer and more efficient programs.

Introduction

Programs don't just store dataβ€”they also perform calculations, compare values and make decisions. This is made possible through operators. Operators are special symbols that tell a program what action to perform with one or more values.

Whether you're adding two numbers, checking if a password is correct or combining multiple conditions, operators are used in almost every program you write. Understanding how they work is an essential step toward writing logical and interactive code.

Why It Matters

Without operators, programs couldn't calculate prices, compare values or make decisions. They allow software to process information and react to different situations, making applications dynamic and useful.

Key Principles

Arithmetic Operators

Arithmetic operators perform mathematical calculations.

Common operators:

  • Addition (+)
  • Subtraction (-)
  • Multiplication (*)
  • Division (/)
  • Modulus (%) β€” Remainder

Example: 10 + 5 = 15

Comparison Operators

Comparison operators compare two values and always return a Boolean (true or false).

Common operators:

  • Equal to (==)
  • Not equal to (!=)
  • Greater than (>)
  • Less than (<)
  • Greater than or equal to (>=)
  • Less than or equal to (<=)

Example: 18 >= 16 β†’ true

Logical Operators

Logical operators combine multiple conditions.

Common operators:

  • AND (&&)
  • OR (||)
  • NOT (!)

Example: Age >= 18 && hasTicket == true

The result is only true if both conditions are true.

Operators Across Popular Languages

Most programming languages use nearly identical operators, making them easy to transfer from one language to another.

  • Python β€” 5 + 3 Β· age >= 18 Β· age >= 18 and member
  • JavaScript β€” 5 + 3 Β· age >= 18 Β· age >= 18 && member
  • TypeScript β€” 5 + 3 Β· age >= 18 Β· age >= 18 && member
  • Java β€” 5 + 3 Β· age >= 18 Β· age >= 18 && member
  • C# β€” 5 + 3 Β· age >= 18 Β· age >= 18 && member
  • C++ β€” 5 + 3 Β· age >= 18 Β· age >= 18 && member
  • Go β€” 5 + 3 Β· age >= 18 Β· age >= 18 && member
  • Rust β€” 5 + 3 Β· age >= 18 Β· age >= 18 && member

Examples

Operators are used every day in software:

  • Calculating the total price of an order.
  • Checking if a password is correct.
  • Determining if a user is over 18.
  • Combining multiple login requirements.
  • Comparing two scores in a game.

Common Mistakes

  • Confusing assignment (=) with comparison (== or ===).
  • Using the wrong comparison operator.
  • Forgetting that comparison operators return a Boolean value.
  • Writing complex expressions that are difficult to read.

Exercises

  • Calculate the result of 12 + 8.
  • Write a comparison that checks if a user is at least 18 years old.
  • Create a logical expression that checks whether a user is logged in and has verified their email.
  • Identify which operator category (Arithmetic, Comparison or Logical) each example belongs to.

Summary

Operators allow programs to calculate values, compare information and combine conditions. The three main categories are Arithmetic Operators, Comparison Operators and Logical Operators. Mastering these operators is essential because they are used in nearly every program you will write.

Introduction

Not every program should behave the same way all the time. Sometimes a user enters the correct password, sometimes they don't. Sometimes a product is in stock, and sometimes it's sold out. Conditions allow programs to make decisions based on different situations.

Conditions evaluate whether something is true or false. Depending on the result, the program chooses which block of code to execute. This makes software interactive and responsive to user input.

Why It Matters

Without conditions, every program would follow exactly the same path every time it runs. Conditions allow applications to react to different inputs, validate information and provide different outcomes based on specific rules.

Key Principles

The if Statement

The if statement runs code only when a condition is true.

Example: If age is greater than or equal to 18 β†’ Allow access

The else Statement

The else statement runs when the condition is false.

Example: If password is correct β†’ Log the user in. Else β†’ Show an error message.

Multiple Conditions

Programs can check several conditions at once using logical operators such as AND (&&) and OR (||).

Example: Age >= 18 AND hasTicket == true

Both conditions must be true before access is granted.

Conditions Across Popular Languages

Although the syntax varies slightly, every programming language uses conditions to make decisions.

  • Python β€” if age >= 18:
  • JavaScript β€” if (age >= 18) {}
  • TypeScript β€” if (age >= 18) {}
  • Java β€” if (age >= 18) {}
  • C# β€” if (age >= 18) {}
  • C++ β€” if (age >= 18) {}
  • Go β€” if age >= 18 {}
  • Rust β€” if age >= 18 {}

Examples

Conditions are used in many applications:

  • Checking whether a user is logged in.
  • Verifying a password.
  • Determining if a customer is eligible for a discount.
  • Showing different content based on age.
  • Preventing access to restricted pages.

Common Mistakes

  • Forgetting that conditions must evaluate to true or false.
  • Mixing up = and ==.
  • Creating conditions that are unnecessarily complicated.
  • Forgetting to handle the else case.

Exercises

  • Write a condition that checks if a user is at least 18 years old.
  • Think of three real-world situations where an if statement could be used.
  • Create an example that uses both if and else.

Summary

Conditions allow programs to make decisions by evaluating whether something is true or false. Using statements like if and else, developers can create software that responds to user input, validates information and behaves differently depending on the situation.

Introduction

Many programming tasks involve repeating the same action multiple times. Imagine displaying 100 products, sending notifications to every user or calculating the total of several numbers. Writing the same code over and over would be slow and inefficient. Loops solve this problem by allowing a block of code to run repeatedly.

Instead of duplicating code, developers use loops to automate repetitive tasks. This makes programs shorter, easier to read and much more efficient.

Why It Matters

Loops are used in almost every application. They allow programs to process lists of data, repeat actions automatically and save developers from writing unnecessary code. Understanding loops is essential for building real-world software.

Key Principles

For Loop

A for loop repeats code a specific number of times.

Example: Repeat 10 times β†’ Print "Hello"

For loops are commonly used when you know exactly how many times something should repeat.

While Loop

A while loop continues running as long as a condition remains true.

Example: While lives > 0 β†’ Continue the game

While loops are useful when you don't know in advance how many times the loop will run.

Looping Through Collections

Loops are often used to go through every item in an array or list, such as Apple, Banana, Orange β€” the program processes each item one by one.

Loops Across Popular Languages

Every programming language supports loops, although the syntax may differ slightly.

  • Python β€” for item in fruits:
  • JavaScript β€” for (let i = 0; i < fruits.length; i++) {}
  • TypeScript β€” for (let i = 0; i < fruits.length; i++) {}
  • Java β€” for (int i = 0; i < fruits.length; i++) {}
  • C# β€” foreach (var item in fruits) {}
  • C++ β€” for (int i = 0; i < size; i++) {}
  • Go β€” for i := 0; i < len(fruits); i++ {}
  • Rust β€” for item in fruits.iter() {}

Examples

Loops are used to:

  • Display every product in an online store.
  • Send emails to multiple users.
  • Calculate the total of a list of prices.
  • Process game objects every frame.
  • Read data from a file.

Common Mistakes

  • Creating infinite loops that never stop.
  • Using the wrong type of loop.
  • Forgetting to update the loop condition.
  • Making loops more complicated than necessary.

Exercises

  • Think of three everyday tasks that involve repetition.
  • Explain when you would use a for loop instead of a while loop.
  • List three situations where a loop could process multiple items.

Summary

Loops allow programs to repeat tasks automatically, making code more efficient and easier to maintain. Whether processing data, displaying information or automating repetitive actions, loops are one of the most powerful tools in programming.

Introduction

As programs grow larger, writing the same code multiple times becomes inefficient and difficult to maintain. Functions solve this problem by grouping reusable code into a single block that can be called whenever it's needed.

Think of a function as a small machine: it receives an input, performs a task and can return an output. Functions help organize code, reduce repetition and make programs easier to understand.

Why It Matters

Functions are used in every programming language and almost every application. They make code reusable, easier to maintain and simpler to debug. Instead of writing the same logic repeatedly, you write it once and use it whenever needed.

Key Principles

Creating a Function

A function is a named block of code that performs a specific task.

Example: Function greet() β†’ Display "Hello!"

Parameters

Functions can receive parameters, which are values passed into the function.

Example: Function greet(name) β†’ Display "Hello, John!"

The parameter allows the same function to work with different values.

Return Values

A function can send information back using a return value.

Example: Function add(a, b) β†’ Return a + b

If a = 5 and b = 3, the function returns 8.

Functions Across Popular Languages

Although the syntax differs, every programming language uses functions to organize and reuse code.

  • Python β€” def greet(name):
  • JavaScript β€” function greet(name) {}
  • TypeScript β€” function greet(name: string) {}
  • Java β€” void greet(String name) {}
  • C# β€” void Greet(string name) {}
  • C++ β€” void greet(string name) {}
  • Go β€” func greet(name string) {}
  • Rust β€” fn greet(name: &str) {}

Examples

Functions are used to:

  • Calculate the total price of an order.
  • Validate a user's password.
  • Send an email.
  • Display information on a webpage.
  • Convert temperatures between Celsius and Fahrenheit.

Common Mistakes

  • Creating functions that are too large.
  • Giving functions unclear names.
  • Forgetting to return a value when needed.
  • Repeating code instead of creating a function.

Exercises

  • Think of three tasks that could be turned into functions.
  • Explain the difference between a parameter and a return value.
  • Write down a descriptive name for a function that calculates a shopping cart total.

Summary

Functions are reusable blocks of code that perform specific tasks. By accepting parameters and returning values, they make programs more organized, efficient and easier to maintain. Learning how to use functions is a major step toward writing clean, professional code.

Introduction

As programs become more advanced, developers need a way to organize larger amounts of data. Instead of creating dozens of separate variables, programming languages provide Arrays and Objects to group related information together.

Arrays store multiple values in a single collection, while Objects describe something by storing different pieces of information about it. Together, they form the foundation of almost every modern application, from websites and games to artificial intelligence.

Why It Matters

Without Arrays and Objects, managing data would quickly become difficult. They allow developers to organize information, access it efficiently and build applications that can handle large amounts of data in a structured way.

Key Principles

Arrays

An Array stores multiple values in a single variable.

Example: ["Apple", "Banana", "Orange"]

Arrays are perfect for lists where every item belongs to the same group, such as:

  • Products
  • Users
  • Messages
  • High scores
Objects

An Object stores multiple pieces of information about one thing.

Example: name: "John", age: 24, country: "USA"

Instead of storing one value, an Object stores properties that describe something.

Arrays & Objects Together

Arrays and Objects are often combined β€” for example, a list of users where each user is its own Object with a name and age. This represents a collection of structured records rather than a flat list of simple values.

Arrays & Objects Across Popular Languages

Every programming language provides a way to group related data. While the syntax differs, the concept remains the same.

  • Python β€” fruits = ["Apple", "Banana"] Β· user = {"name": "John", "age": 24}
  • JavaScript β€” const fruits = ["Apple", "Banana"]; Β· const user = { name: "John", age: 24 };
  • TypeScript β€” const fruits: string[] = ["Apple"]; Β· const user = { name: "John", age: 24 };
  • Java β€” String[] fruits = {"Apple", "Banana"}; Β· class User { ... }
  • C# β€” string[] fruits = {"Apple", "Banana"}; Β· class User { ... }
  • C++ β€” vector<string> fruits; Β· struct User { ... };
  • Go β€” fruits := []string{"Apple", "Banana"} Β· type User struct { ... }
  • Rust β€” let fruits = vec!["Apple", "Banana"]; Β· struct User { ... }

Examples

Arrays and Objects are used everywhere:

  • A shopping cart stores products in an Array.
  • A playlist stores multiple songs in an Array.
  • A user profile is represented as an Object.
  • A product contains properties like name, price and stock.
  • Social media apps store lists of posts, comments and users.

Common Mistakes

  • Using an Array when an Object is more appropriate.
  • Storing unrelated data in the same Object.
  • Creating unnecessary nested Arrays or Objects.
  • Forgetting that Arrays store collections while Objects describe individual items.

Exercises

  • Create an Array containing your five favorite movies.
  • Describe yourself using an Object with your name, age and country.
  • Think of three real-world examples where Arrays and Objects are used together.
  • Explain the difference between an Array and an Object in your own words.

Summary

Arrays and Objects are essential data structures used in every programming language. Arrays organize collections of values, while Objects group related information about a single item. Together, they allow developers to build structured, scalable and efficient applications that manage real-world data.