Home › The Stash

Programming Basics Explained: Variables, Loops and Functions (Tech+)

ReferenceOctober 31, 2026

ExplainerLevel beginnerTime ~15 minTool Python, PowerShellCost freeExam Tech+ 4

What you’ll know

What variables, data types, branches, loops, functions and objects are; the difference between compiled, interpreted, query and markup languages; how to plan a program with pseudocode or a flowchart; and how to run your first script.

Why it matters. You don’t need to become a developer, but IT jobs are full of scripts: a PowerShell one-liner to reset a password, a Python script that checks a log. Reading code calmly starts here.

The building blocks

Idea What it is Example
Variable A named box that holds a value that can change age = 17
Constant A named value that should never change MAX_TRIES = 3
Data types The kind of value in the box integer 17, float 3.5, string "Nova", char 'A', Boolean True/False
Array / list Many values in one variable, in order tickets = ["printer", "Wi-Fi"]
Branch (if/else) Do one thing or another depending on a test if age >= 18: … else: …
Loop Repeat steps: a fixed number of times (for) or while something stays true (while) for t in tickets: …
Function A named, reusable set of steps that can take inputs and return a result def greet(who): …
Object A bundle of data (properties) and actions (methods) a date has a .Year property and an .AddDays() method

Kinds of language

Kind How it runs Examples
Compiled Turned into a program file before it runs; usually fast C, C++, Go, Rust
Interpreted / scripting Read and run line by line by an interpreter; quick to write and change Python, JavaScript, PowerShell, Bash
Query Asks a database for data SQL
Markup Describes how content is laid out; not really programming HTML, XML, Markdown
Assembly Human-readable CPU instructions, one step above binary x86 or ARM assembly

Plan first: pseudocode and flowcharts

Pseudocode is the program written in plain English before any real code:

pseudocode
IF the user is 18 or older
    SHOW "Adult"
OTHERWISE
    SHOW "Not yet"

A flowchart draws the same thing with standard shapes:

Shape Means
Oval Start or end
Rectangle A step (process)
Diamond A decision with yes/no arrows
Parallelogram Input or output
Arrow The direction the program flows

Nova wrote pseudocode for her morning: IF coffee THEN function. ELSE stay in bed. It compiled perfectly. Every single time. — Nyx

Try it: your first script

Save this as basics.py (Notepad works; choose All files when saving). It uses a variable, a list, a function, a branch and a loop:

basics.py
name = "Nova"           # a variable holding a string
age = 17                # an integer
tickets = ["printer", "Wi-Fi", "password"]   # a list (array)

def greet(who):         # a function
    return "Hello, " + who

print(greet(name))
if age >= 18:           # branching
    print("Adult")
else:
    print("Not yet")
for t in tickets:       # a loop
    print("Ticket:", t)
Run it (Windows PowerShell or Linux/WSL)
PS> python basics.py
 Hello, Nova
 Not yet
 Ticket: printer
 Ticket: Wi-Fi
 Ticket: password

On Linux or WSL type python3 basics.py. No Python on Windows? Typing python opens the Microsoft Store page for it, or get it from python.org. Now change age = 17 to 18 and run it again: the branch takes the other path.

Objects in PowerShell
PS> (Get-Date '2026-10-31').Year
 2026
PS> (Get-Date '2026-10-31').AddDays(7).ToString('yyyy-MM-dd')
 2026-11-07

A date is an object: .Year reads one of its properties, and .AddDays(7) runs one of its methods.

Where this fits

This is part of the free CompTIA Tech+ roadmap: computer basics in the order the exam teaches them.

NextProgramming languages compared→

Go deeper

Explainer, written by StashGrid with AI help and checked against the CompTIA Tech+ (FC0-U71) exam objectives before publishing. Every command was run on a Windows 11 PC and in Ubuntu 24.04 (WSL) on 30 Oct 2026. StashGrid isn’t affiliated with CompTIA. Spotted an error? Tell us.