</>Learn to Write Code
LearnPseudocodeReal CodeLanguagesVideosCode TalkAbout
Learn → Programming Fundamentals → Input, Output & Comments

Programming Fundamentals

01Variables02Operators03Input & Output04Sequence05Conditions06Loops07Functions08Objects
Lesson 3 of 8·Beginner

Input, Output & Comments

Talk to the user: ask for information, show results, and leave notes for humans reading the code.

Related:inputoutputcommentpromptconsole

Programs need ways to communicate

Input is information coming into the program. Output is information going out of the program. A comment is a note for people reading the code; the computer ignores it.

A simple program can ask your name, remember the answer, and then greet you.

Try it: Think of one question a program could ask you and one thing it could display afterward.

Ask, save, then show

The steps are more important than the syntax: ask a question, save the answer, then use it.

Pseudocode
EXPLANATION Ask the user for a name
ASK "What is your name?" SAVE IN playerName
SHOW "Hello, " + playerName

The same idea in Python

input() asks for text and print() displays output. A # begins a single-line comment.

Python
# Ask the user for a name
playerName = input("What is your name? ")
print("Hello, " + playerName)

The same idea in JavaScript

In a browser, prompt() can collect simple input and console.log() can display output to the developer console.

JavaScript
// Ask the user for a name
const playerName = prompt("What is your name?");
console.log("Hello, " + playerName);

The same idea in C#

Console.ReadLine() reads text typed by the user.

C#
// Ask the user for a name
Console.Write("What is your name? ");
string playerName = Console.ReadLine() ?? "";
Console.WriteLine("Hello, " + playerName);

The same idea in Java

Java commonly uses Scanner for console input.

Java
// Ask the user for a name
Scanner input = new Scanner(System.in);
System.out.print("What is your name? ");
String playerName = input.nextLine();
System.out.println("Hello, " + playerName);
A complete Java file would also import java.util.Scanner.

The same idea in C++

std::getline reads a full line of text from standard input.

C++
// Ask the user for a name
std::string playerName;
std::cout << "What is your name? ";
std::getline(std::cin, playerName);
std::cout << "Hello, " << playerName << '\n';
Lesson 3 of 8 · Concept
← Previous Lesson: OperatorsNext Lesson: Sequence →

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.