Your First Program
Prerequisites: Installing Julia
Create a file named hello.jl and run it with julia hello.jl:
println("Hello, world!")
println("Welcome to Julia.")
Expected output
Hello, world!
Welcome to Julia.
printlnprints its arguments and then a new line.- Strings go in double quotes. Single quotes are for a single
character, like
'a'. - No semicolons, no
mainfunction: Julia runs a file from top to bottom.
print, println, and several values
print("Loading")
print("...")
println(" done")
println("Answer: ", 42)
println(1, 2, 3)
Loading... done
Answer: 42
123
print doesn't add a new line. Both functions glue several arguments
together without spaces, so add the spaces yourself.
@show
x = 6 * 7
@show x
@show x + 1
x = 42
x + 1 = 43
@show prints an expression and its value — the quickest way to peek
at what your code is doing. (The @ marks a macro; you'll write your
own in Level 3.)
Practice
Write a program that prints your name on one line and your favorite
food on the next, then uses @show to print 2 + 2.
Show solution
println("Ada")
println("Pizza")
@show 2 + 2
Ada
Pizza
2 + 2 = 4