Open In App
Related Articles

Julia break Keyword | Exiting from a loop in Julia

Improve Article
Improve
Save Article
Save
Like Article
Like

Keywords in Julia are predefined words that have a definite meaning to the compiler. These keywords can’t be used to name variables.

'break' keyword in Julia is used to exit from a loop immediately. Whenever the break keyword is executed, the compiler immediately stops iterating over further values and sends the execution pointer out of the loop.
Syntax:

loop condition
    statement
    statement
    break
    statement
end

Example 1:




# Julia program to illustrate
# the use of 'break' keyword
  
# Defining for-loop
for i in 1:10
    if i == 6  
        # Using 'break' keyword
        break
    else
        println(i)
    end
end


Output:

1
2
3
4
5

Example 2:




# Julia program to illustrate
# the use of 'break' keyword
  
i = 0
  
# Defining while-loop
while true
    global i = i + 1
    if i == 6
        # Using 'break' keyword
        break
    else
        println(i)
    end
end


Output:

1
2
3
4
5


Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 26 Mar, 2020
Like Article
Save Article
Previous
Next
Similar Reads