Skip to content
AgileLogics
5 min read

Your First Program

Prerequisites: Getting Set Up

In a new notebook, type this and press Shift + Enter:

Print["Hello, world!"]
Hello, world!
  • Print is a function. Function names start with a capital letter, and arguments go in square brackets.
  • Text goes in double quotes — it's a string.

Every input has a value

In a notebook you rarely need Print: every input's value is shown automatically.

2 + 3
"Hello" <> ", " <> "world"
Range[10]
StringReverse["stressed"]
5
Hello, world
{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
desserts
  • <> joins strings.
  • Range[10] makes a list of the numbers 1 to 10. Lists use curly braces.

How output is shown in this course

When a code block has several lines, each line is a separate input (as if you evaluated each in its own cell, or ran it in the wolframscript prompt), and the output block lists their results in order. Results are written as plain text:

  • A notebook typesets results: x^2 appears with a real superscript, 1/2 as a stacked fraction, Sqrt[2] with a root sign.
  • Strings in results are shown without quotes, exactly as notebooks display them — desserts, not "desserts".
  • Approximate numbers are shown with six significant digits by default, as notebooks do: 3.14159.

Multiplication by a space

x = 7;
3 x
3*x
21
21

A space between two things means multiplication, as in math. The semicolon after x = 7 hides that input's result.

Scripts

In a .wls script run with wolframscript -file, results are not shown automatically — use Print:

Print["The answer is ", 6*7]
The answer is 42

Practice

Print your name, then compute how many seconds there are in a day.

Show solution
Print["Ada"]
24*60*60
Ada
86400