LogoLogo
Computing Skills
Computing Skills
  • Introduction
  • File Directory Structures
  • Text Editors
  • GitHub
  • Unix
  • Julia
    • Installation
    • REPL
    • Basic Syntax
    • Numbers and Math
    • Strings and Characters
    • Regular Expressions
    • Control Flow
    • Collections and Data Structures
    • File Input/Output
    • Packages
    • DataFrames
    • JuliaPlots
    • ScikitLearn.jl
    • JuliaStats
    • Exercises
  • Python
    • Installation
    • REPL
    • Basic Syntax
    • Numbers and Math
    • Strings and Characters
    • Regular Expressions
    • Control Flow
    • Collections and Data Structures
    • File Input/Output
    • Packages
    • Data Frames and Data Manipulation
  • R
    • Installation
    • REPL
    • Basic Syntax
    • Numbers and Math
    • Strings and Characters
    • Regular Expression
    • Control Flow
    • Collections and Data Structures
    • File Input/Output
    • Packages
    • DataFrames
    • Data Analysis and Manipulation
Powered by GitBook
On this page
  • "Hello, World!" Program
  • Variable Assignment
  • Comments
  • Print Statements
  • Exercises
  • Resources
Export as PDF
  1. Julia

Basic Syntax

PreviousREPLNextNumbers and Math

Last updated 6 months ago

"Hello, World!" Program

This is the typical first program for those new to a general purpose programming language like Julia. It can be used to test that the of Julia is working and also introduce Julia's basic syntax using the environment or running code written using a at the command line.

Input:

# hello.jl
# This is a single line comment
#= 
This is a block comment to show
comments across multiple lines.
=#

print("Hello, World!")

Output:

Hello, World!

Here are variations of the "Hello, World!" programming using variables and different print statements.

Input:

# hello2.jl

greeting = "Hello, World!"

print(greeting) # print greeting
print("Greeting 1: $greeting") # print greeting as part of a string phrase
print("Greeting 2: $greeting\n") # print with newline (\n) character
println("Greeting 3: $greeting") # println automatically adds the newline character

Output:

Hello, World!
Greeting 1: Hello, World!
Greeting 2: Hello, World!

Greeting 3: Hello, World!

Variable Assignment

In order to assign variables in Julia, you write the desired name for your variable, an = sign, and what the value of the variable should be.

Input:

x = 7
x

Output:

7

Comments

  • We can write comments on our code, which do not run, to describe what certain lines of code or section of code do

    • These comments are just for the programmer, they will not appear anywhere in the output and just are there to explain what the code is doing or to provide helpful notes

    • To make a comment in Julia, you can use the “#” symbol and then type your comment

  • Sometimes you might want to write longer comments that span multiple lines – to do this you can surround these comments with #= above the start as well as =# below the end

Input:

# Assigns variable x to have value 7
x = 7

#=
Now we want to print out what x is. We can do this by simply typing x and 
hitting run. This comment spans multiple lines. These types of comments are 
useful when describing complex functions or algorithms.
=#

x

Output:

7

Print Statements

Without using a print statement, Julia will only print out the most recent item that has an output. In order to print multiple things, we can use the print() or println() functions.

Input:

# Assign x, y, and z variables 
x = 7
y = 10
z = 4

z
(x)
println(y)

Output:

7
10

Exercises

  • Use Julia in Brown Oscar Computing Environment - Forthcoming!

  • Use Julia in Brown Stronghold Computing Environment - Forthcoming!

Resources

Julia Documentation:

Julia Documentation:

Think Julia:

Think Julia:

Installation
REPL
Text Editor
Unix
Variables
Scope of Variables
Chapter 1 - The Way of the Program
Chapter 2 - Variables, Expressions and Statements