(Julia) 在 IF 语句中分配变量时无法使用分号抑制输出

(Julia) Not able suppress output using semicolon when assigning variable inside an IF statement

为什么在IF ELSE语句中加分号无法抑制输出显示?

Unable to suppress output

确实如Julia Manual explains:

If an expression is entered into an interactive session with a trailing semicolon, its value is not shown.

但是,这个语句是指整个输入的表达式。在你的情况下,整个表达式包括 if 部分,所以你应该写:

if condition
    ...
else
    ...
end;

(注意 end 后的分号)

特别注意,正如 Julia 手册中 here 所解释的那样:

if blocks also return a value, which may seem unintuitive to users coming from many other languages. This value is simply the return value of the last executed statement in the branch that was chosen

end 之后放置 ; 会禁止打印 if 块返回的值。