有时,需要相互之间嵌入多个 if 语句,这在其他编程语言中也是可能的。在Erlang中,这也是可能的。
Nested if - 示例
-module(helloLearnfk). -export([start/0]).start() -> A=4, B=6, if A < B -> if A > 5 -> io:fwrite("A is greater than 5"); true -> io:fwrite("A is less than 5") end; true -> io:fwrite("A is greater than B") end.
上面的代码输出将是-
A is less than 5