Open In App

Julia Keywords

Improve
Improve
Like Article
Like
Save
Share
Report

Keywords in Julia are reserved words that have a predefined meaning to the compiler. They are used for some internal processes by the compiler. Keywords can’t be used as a variable name. Doing the same will result in a compile-time error.
Example:




# Julia program to illustrate
# the use of keywords
  
# Using 'for' keyword 
for i in 1:10
      
    # Using if keyword
    if i % 2 == 0
        println(i, " is even")
      
    # Using else keyword
    else
        println(i, " is odd")
      
    # Using end keyword
    end
end


Output

1 is odd
2 is even
3 is odd
4 is even
5 is odd
6 is even
7 is odd
8 is even
9 is odd
10 is even

If we use a keyword as a variable name, the compiler will generate an error:
Keywords-in-Julia-01

Important keywords in Julia

baremodule
begin
break
catch
const
continue
do
else
elseif
end
export
false
finally
for
function
global
if
import
let
local
macro
module
quote
return
struct
true
try
using
while
 

There are some keywords like abstract type, mutable struct, primitive type which are reserved but creation of variables with abstract, mutable, primitive and type is possible.
Keywords-in-Julia-02


Last Updated : 26 Mar, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads