</>Learn to Write Code
LearnPseudocodeReal CodeLanguagesVideosCode TalkAbout
Learn → Programming Fundamentals → Functions & Reuse

Programming Fundamentals

01Variables02Operators03Input & Output04Sequence05Conditions06Loops07Functions08Objects
Lesson 7 of 8·Beginner

Functions & Reuse

Give a reusable set of instructions a name, call it when needed, and optionally get a result back.

Related:functionmethodactionparameterreturn

A function is a reusable helper

A function is a named group of instructions you can use again without rewriting them.

You can give a function information to work with, called parameters. The function can SEND a result BACK to the code that called it.

Think of a calculator button: give it inputs, let it do one job, then get the answer back.
Try it: What two pieces of information would an ACTION named CalculateArea need for a rectangle?

Create an ACTION and call it

This action accepts two numbers, adds them, and sends the result back.

Pseudocode
ACTION AddNumbers WITH firstNumber, secondNumber
    CREATE result AS firstNumber + secondNumber
    SEND result BACK
END ACTION

CREATE total AS CALL ACTION AddNumbers WITH 4, 6
SHOW total

The same idea in Python

Python defines a function with def and sends a result back with return.

Python
def addNumbers(firstNumber, secondNumber):
    result = firstNumber + secondNumber
    return result

total = addNumbers(4, 6)
print(total)

The same idea in JavaScript

JavaScript uses function and return for the same reusable helper.

JavaScript
function addNumbers(firstNumber, secondNumber) {
    const result = firstNumber + secondNumber;
    return result;
}

const total = addNumbers(4, 6);
console.log(total);

The same idea in C#

C# declares the parameter types and the type of value the method returns.

C#
static int AddNumbers(int firstNumber, int secondNumber)
{
    int result = firstNumber + secondNumber;
    return result;
}

int total = AddNumbers(4, 6);
Console.WriteLine(total);

The same idea in Java

Java uses typed parameters and return values in a similar way.

Java
static int addNumbers(int firstNumber, int secondNumber) {
    int result = firstNumber + secondNumber;
    return result;
}

int total = addNumbers(4, 6);
System.out.println(total);

The same idea in C++

C++ also declares the input and return types.

C++
int addNumbers(int firstNumber, int secondNumber)
{
    int result = firstNumber + secondNumber;
    return result;
}

int total = addNumbers(4, 6);
std::cout << total << '\n';
Lesson 7 of 8 · Concept
← Previous Lesson: LoopsNext Lesson: Objects →

Learn to Write Code

Learn the idea first, write it in pseudocode, then see how real programming languages express the same logic.

Learn

CurriculumPseudocode StandardLanguagesReal Code

Elsewhere

Code TalkAbout BriancodeBetter on YouTubeSupporting files on GitHubAdvertising & Promotions
© 2026 Learn to Write Code. Educational content and examples are provided for learning purposes.