How do I exit a function early and return nothing?

I have a function that takes a dataframe and performs some basic calculations. Sometimes when performing said calculations the data frame becomes empty (the details don’t matter). I’m having trouble checking if the dataframe is empty and returning nothing. My code is below:

function do_stuff(my_dataframe)

    # Nifty calculations

    if nrow(my_dataframe) == 0:


    # More calculations here

    return my_datafram


For some reason, julia is throwing this error: LoadError: syntax: incomplete: “function” at /home/ec2-user/environment/my_file.jl:17 requires end

Is there a syntax error? Is there a proper way to interrupt a function?

Your syntax is wrong. Julia does not have the same syntax as python. if statements are not whitespace sensitive and need an end to complete the block.

You should try to work. See this section in the manual. Hopefully someone else here can recommend to you are good introductory tutorial for people coming from python.


My code is working now, thank you! I thought the “end” blocks only applied to functions. I need to read the manual more carefully.

1 Like