It is unclear what you mean here, but it is probably not correct. Where did you encounter this?
if and begin don’t short-circuit anything, but it is correct that their value is the value of the last contained expression.
The compiler may optimize out certain expressions if it can prove that this does not change anything. Eg in
julia> function donothing(x)
y = x^2 + 9*x - 1
x
end
donothing (generic function with 1 method)
julia>
julia> @code_llvm donothing(1)
; @ REPL[4]:2 within `donothing'
define i64 @julia_donothing_16331(i64) {
top:
; @ REPL[4]:3 within `donothing'
ret i64 %0
}
They cost nothing when the result is not used, at least in local scope.
They of course cost something when you run them in the repl, I.e. the printing in the repl is not free, but that can be suppressed with ; as usual.
Please don’t suggest that when it’s unnecessary, if anything the typed and optimized Julia ir should be enough to show the optimization.
Note that the dead code elimination isn’t even relevant here. In both cases the op are comparing, the results are unused. (Either the result of the last expression being unused by the enclosing block or the result of the block, I.e. the result of the last expression being unused by the “caller”).