关键字if,elseif,else,endif
输入
{numer = 5}{denom = 4}{if(numer == 0)}The numerator is 0, so theresult is 0.{elseif(denom == 0)}The denominator is 0, so aresult is impossible.{else}The result is: {numer/denom}.{endif}
输出
Output:The result is: 1.25.
输入
{x = 5; y = 4}{if(x % y) }The remainder is {x % y}.{else}{x} is a multiple of {y}.{endif}
输出
Output:The remainder is 1.
通过判断传入的运算符采用不同的计算方式并返回结果
{num1 = 10}{num2 = 5}{operation = "divide"}{if(operation == "add")}Result of addition: {num1 + num2}{elseif(operation == "subtract")}Result of subtraction: {num1 - num2}{elseif(operation == "multiply")}Result of multiplication: {num1 * num2}{elseif(operation == "divide")}{if(num2 == 0)}Division by zero is not possible.{else}Result of division: {num1 / num2}{endif}{else}Unknown operation.{endif}
我们可以把相同的代码写成函数的形式
{define user_calculate(num1, num2, operation)}{if(operation == "add")}Result of addition: {num1 + num2}{elseif(operation == "subtract")}Result of subtraction: {num1 - num2}{elseif(operation == "multiply")}Result of multiplication: {num1 * num2}{elseif(operation == "divide")}{if(num2 == 0)}Division by zero is not possible.{else}Result of division: {num1 / num2}{endif}{else}Unknown operation.{endif}{enddefine}{num1 = 10086}{num2 = 5}{operation = "divide"}{user_calculate(num1,num2,operation)}