Variables and expressions
Give values names in BASIC, work with numeric expressions, and use string variables with a dollar-sign suffix.
Try these BASIC examples in the Web IDE Terminal.
Give a value a name
A variable lets a program remember a value. Assignment evaluates the expression on the right of = and stores it under the name on the left.
x = 25
PRINT x * 4The numeric result is 100. Classic BASIC numeric output may include spacing; the value is the point of this example.
Store some text
In classic BASIC syntax, a dollar sign at the end of a variable name marks a string variable. Use + to join strings.
name$ = "Cortex"
PRINT "Hello, " + name$ + "."The expected text is Hello, Cortex.. A string is text, even when it contains digits.
Make the calculation clear
Expressions combine values, variables, and operators. Parentheses make the intended grouping explicit.
rectWidth = 12
rectHeight = 8
area = rectWidth * rectHeight
perimeter = 2 * (rectWidth + rectHeight)
PRINT area
PRINT perimeterThe numeric results are 96 and 40. Cortex uses QBASIC-style typing and coercion rules. Use HELP in Terminal for language reference entries.
Try another value
Change width or height and predict both results before running the program. Then learn how to repeat work with a loop.