Chapter 1: The Basics - Your First REDLINE Program
This chapter covers the fundamental building blocks of any REDLINE program.
"Hello, World!" with print()
The traditional first step in any language is to make it talk. In REDLINE, this is a single, clean line.
print("Hello, World!")
This calls the built-in print function, which outputs the given string to the console, followed by a newline character.
Comments: Leaving Notes for Your Future Self
Use the # symbol for single-line comments. The compiler will ignore them completely. Good comments explain the why, not the what. If your code is so complex you have to explain what it does, you probably wrote it wrong.
# Calculate the velocity based on a fixed acceleration.
val velocity: float = initial_velocity + (acceleration * time) # a = 9.8
Variables and Constants: var vs. val
REDLINE forces you to be intentional about your data. This is a core feature for writing safe and predictable code.
val(Value): Creates an immutable constant. Once you assign a value to it, it can never be changed. This is the default you should always reach for. It signals to other developers (and the compiler) that this piece of data is a fixed point.var(Variable): Creates a mutable variable. You can update its value later. Use this only when you know the data must change during its lifetime.
val LAUNCH_CODE: string = "Project-A-113" # A constant. Cannot be changed.
var reactor_temp: int = 900 # A variable that will fluctuate.
reactor_temp = 950 # This is valid.
# LAUNCH_CODE = "New-Code" # This would cause a compiler error.
Preferring val makes your code easier to reason about and helps prevent a whole class of bugs caused by accidental modification of data.
Core Data Types
REDLINE is a strictly typed language. You must declare the type of your data. This eliminates runtime errors where you might, for example, try to do math on a string.
| REDLINE Type | C++ Equivalent | Description |
|---|---|---|
int |
int |
Whole numbers, positive or negative. |
float |
double |
64-bit floating-point (decimal) numbers. |
string |
std::string |
A sequence of characters. |
bool |
bool |
Logical values: true or false. |
void |
void |
Represents the absence of a value. |
Chapter 2: Control Flow - Making Decisions and Looping
This is where your programs stop being a straight line and start adapting to changing conditions.
If/Else
Use if and else to execute code based on a condition. The colon (:) and indentation are mandatory and define the code blocks.
val shield_integrity: float = 0.45
if shield_integrity < 0.5:
print("Warning: Shields are below 50%.")
else:
print("Shields are holding strong.")
While Loops
A while loop runs as long as its condition evaluates to true. Make sure something inside the loop eventually causes the condition to become false, or you've just invented an infinite loop.
var countdown: int = 10
while countdown > 0:
print(f"T-minus {countdown}")
countdown = countdown - 1
print("Liftoff!")
For Loops
The for loop is the workhorse for iteration. It walks through a sequence or a range of numbers.
# Iterate over a range (0 to 4)
for i in range(5):
print(f"Iteration: {i}")
# Iterate over a list
val crew: list[string] = ["Alice", "Bob", "Charlie"]
for member in crew:
print(f"Crew member: {member}")
Break and Continue
break: Exit the loop immediately.continue: Skip the rest of this iteration and jump to the next one.
for i in range(100):
if i == 42:
print("Found the answer!")
break
if i % 2 == 0:
continue # Skip even numbers
print(i)