Julia continue Keyword | Continue iterating to next value of a loop in Julia

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

'continue' keyword in Julia skips the statement immediately after the continue statement. Whenever the continue keyword is executed, the compiler immediately stops iterating over further values and sends the execution pointer back to the next iterating value in the loop.

Syntax:

loop condition
    statement
    statement
    continue
    statement
end

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

1
3
5
7
9

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

# Julia program to illustrate
# the use of 'continue' keyword
   
i = 0
   
# Defining while-loop
while i < 10
    global i = i + 1
    if iseven(i)
        # Using 'continue' keyword
        continue
    else
        println(i)
    end
end

chevron_right


Output:

1
3
5
7
9

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.