Mathematica 9 is now available

Switch

Usage

Switch[expr,  ,  ,  ,  , ... ] 计算 expr, 然后轮流和每个  比较,计算并返回相应于找到的第一个匹配的  .


Notes

• 只有相应于第一个与expr匹配的   被计算.仅当进行匹配尝试时,每个  被计算.
• 如果最后一个  是 pattern _, 则如果达到这种情况,相应的  总是不计算返回.
• 如果没有一个  匹配 expr, Switch不计算返回.
Switch 有属性 HoldRest.
• 可以在 Switch中使用Break, ReturnThrow.
• 参见Mathematica 全书: 2.5.8.
• 同时参见: If, Condition, Which.
Further Examples

The output of this function depends on the type of the input.

In[1]:=  

In[2]:=  

Out[2]=

In[3]:=  



Any questions about topics on this page? Click here to get an individual response.Buy NowMore Information
THIS IS DOCUMENTATION FOR AN OBSOLETE PRODUCT.
SEE THE DOCUMENTATION CENTER FOR THE LATEST INFORMATION.