秘密一
JSL If 語句其實是一個函數,它會傳回一個值。
print( if ( 1 < 2, "yes", "no" ) )
“是的”
如果你不知道這一點,你可能會寫
if ( 1 < 2, print("yes"), print( "no" ) )
這也有效。
秘密二
JSL If 函數需要至少兩個論點。 可以有三個以上! 如果有奇數個參數,則最後一個是否則價值。
n = 17;
classification = if(
n<3, "toddlers",
n<13, "children",
n<20, "teens",
"adults"
);
show( n, classification );
n = 17;
分類=「青少年」;
秘密三
JSL If 函數將缺失值處理為既不為真也不為假。 這否則價值不是答案。
n = .;
classification = if(
n<3, "toddlers",
n<13, "children",
n<20, "teens",
"adults"
);
show( n, classification );
n = .;
分類=.;
如果您認為兩個缺失值彼此相等,這可能看起來相當令人驚訝。 如果其中一個(或兩個)操作數缺少值,JMP 的比較運算子都會傳回缺失值。 JMP 使用 isMissing 函數來測試缺失:
n = .;
classification = if(
isMissing(n), "unknown",
n<3, "toddlers",
n<13, "children",
n<20, "teens",
"adults"
);
show( n, classification );
n = .;
分類=“未知”;
秘密四
其實沒有什麼秘密,一切都在網路。