🎓 A1Learner
🔍
0 of 54 lessons completed

Elixir Get Started

A script is an Elixir program saved in a text file. Running the file makes the computer follow the instructions inside it.

A saved file runs as a program

Save this line in a file named hello.exs. Run it by typing elixir hello.exs in the terminal.

IO.puts("Saved and running")

Statements run in order

This file holds two statements. The top statement runs first.

IO.puts("Line one")
IO.puts("Line two")

A script can print numbers

A saved script prints numbers in the same way as text. Each value appears on its own line here.

IO.puts(100)
IO.puts(200)

Example

IO.puts("Starting")
IO.puts("Working")
IO.puts("Finished")

Key points

  • Script: an Elixir program saved in a text file.
  • Terminal: a window where you type commands for the computer.
  • Interpreter: the program that reads an Elixir script and carries out its instructions.
  • Extension: an Elixir script name ends in .exs, such as hello.exs.
  • Run command: typing elixir and the file name in the terminal runs the script.
  • Statement: one instruction in a program.
  • Order: statements in a script run from top to bottom.

In this example, the script holds three statements in a file. The first statement prints Starting. The second prints Working, and the third prints Finished, in the same order as the file.

Try it Yourself

Edit the code, then press Run.

Running is simulated

Exercise

How do you run a script saved in a file named hello.exs?