Julia end Keyword | Marking end of blocks in Julia

Keywords in Julia are reserved words that have a pre-defined meaning to the compiler. These keywords can’t be used as a variable name.

'end' keyword in Julia is used to mark the end of a block of statements. This block can be of any type like struct, loop, conditional statement, module, etc.

Syntax:

block_type block_name
    Statement
    Statement
end

Example:

filter_none

edit
close

play_arrow

link
brightness_4
code

# Julia program to illustrate
# the use of 'end' keyword
  
# Defining a function
function fn()
      
    # Defining for-loop
    for i in 1:5
      
        # Using if-else block
        if i % 2 == 0
            println(i, " is even");
        else
            println(i, " is odd");
              
        # Marking end of if-else
        end
          
    # Marking end of for-loop
    end
      
# Marking end of function    
end
   
# Function call
fn()

chevron_right


Output:



1 is odd
2 is even
3 is odd
4 is even
5 is odd

Note: 'end' can also be used to mark the last index in a 1D array.

Example:

filter_none

edit
close

play_arrow

link
brightness_4
code

# Julia program to illustrate
# the use of 'end' keyword
  
# Defining Array
Array1 = Array([1, 2, 3, 4, 5])
  
# Printing last element using 'end' keyword
println("Last element of Array: ", Array1[end])

chevron_right


Output:

Last element of Array: 5



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.