📄 m2_op_conditional.hlp
字号:
{smcl}
{* 07apr2005}{...}
{cmd:help m2 op_conditional}
{hline}
{* index operators}{...}
{* index conditional operator}{...}
{title:Title}
{p 4 4 2}
{hi:[M-2] op_conditional -- Conditional operator}
{title:Syntax}
{it:a} {cmd:?} {it:b} : {it:c}
{p 4 4 2}
where {it:a} must evaluate to a real scalar, and {it:b} and {it:c} may
be of any type whatsoever.
{title:Description}
{p 4 4 2}
The conditional operator returns {it:b} if {it:a} is true ({it:a} is
not equal to 0) and {it:c} otherwise.
{title:Remarks}
{p 4 4 2}
Conditional operators
{cmd:dof = (k==0 ? n-1 : n-k)}
{p 4 4 2}
are more compact than the {cmd:if}-{cmd:else} alternative
{cmd:if (k==0) dof = n-1}
{cmd:else dof = n-k}
{p 4 4 2} and they can be used as parts of expressions:
{cmd:mse = ess/(k==0 ? n-1 : n-k)}
{title:Conformability}
{it:a} {cmd:?} {it:b} : {it:c}:
{it:a}: 1 {it:x} 1
{it:b}: {it:r1 x c1}
{it:c}: {it:r2 x c2}
{it:result}: {it:r1 x c1} or {it:r2 x c2}
{title:Diagnostics}
{p 4 4 2}
In {it:a} {cmd:?} {it:b} : {it:c}, only the necessary parts are evaluated:
{it:a} and {it:b} if {it:a} is true, or {it:a} and {it:c} if {it:a} is false.
However, the {cmd:++} and {cmd:--} operators are always evaluated:
{cmd:(}{it:k}{cmd:==0 ?} {it:i}{cmd:++ :} {it:j}{cmd:++)}
{p 4 4 2}
increments both {it:i} and {it:j}, regardless of the value of {it:k}.
{title:Also see}
{p 4 13 2}
Manual: {hi:[M-2] op_conditional}
{p 4 13 2}
Online: help for
{bf:{help m2_exp:[M-2] exp}};
{bf:{help m2_intro:[M-2] intro}}
{p_end}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -