ifelse(condition::Bool, x, y)

Return x if condition is true, otherwise return y. This differs from ? or if in that it is an ordinary function, so all the arguments are evaluated first. In some cases, using ifelse instead of an if statement can eliminate the branch in generated code and provide higher performance in tight loops.


julia> i = 10
       if i > 10
         println("i is bigger than 10.")
       elseif i < 10   
         println("i is smaller than 10.")
       println("i is 10.")
i is 10.

See Also

all, all!, angle, any, any!, falses, ifelse, is, isinf, isinteger, isnan, isperm, ispow2, isreal, trues,

User Contributed Notes

Add a Note

The format of note supported is markdown, use triple backtick to start and end a code block.

*Required Field

Checking you are not a robot: