1 <!DOCTYPE html PUBLIC
"-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
4 <meta http-equiv=
"Content-Type" content=
"text/html; charset=UTF-8">
5 <meta http-equiv=
"Content-Style-Type" content=
"text/css">
7 <meta name=
"Generator" content=
"Cocoa HTML Writer">
8 <meta name=
"CocoaVersion" content=
"824.44">
9 <style type=
"text/css">
10 p
.p1
{margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Helvetica
}
11 p
.p2
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
; min-height: 12.0px}
12 p
.p3
{margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica
}
13 p
.p4
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
}
14 p
.p5
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
; color: #952e14}
15 p
.p6
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
; color: #606060}
16 span
.s1
{color: #606060}
17 span
.s2
{color: #000000}
18 span
.Apple-tab-span
{white-space:pre
}
22 <p class=
"p1"><b>switch
</b></p>
23 <p class=
"p2"><br></p>
24 <p class=
"p3">object.switch( test1, trueFunc1, test2, trueFunc2 ... testN, trueFuncN, defaultFunc )
</p>
25 <p class=
"p2"><br></p>
27 <p class=
"p2"><br></p>
28 <p class=
"p4">a =
4.switch(
</p>
29 <p class=
"p4"><span class=
"Apple-tab-span"> </span>0, {
<span class=
"s1">"was 0"</span> },
</p>
30 <p class=
"p4"><span class=
"Apple-tab-span"> </span>1, {
<span class=
"s1">"was 1"</span> },
</p>
31 <p class=
"p5"><span class=
"s2"><span class=
"Apple-tab-span"> </span></span>// test cases are evaluated
</p>
32 <p class=
"p4"><span class=
"Apple-tab-span"> </span>{
1 +
1 }, {
<span class=
"s1">"was 2"</span> },
</p>
33 <p class=
"p4"><span class=
"Apple-tab-span"> </span>4, {
<span class=
"s1">"was 4"</span> },
</p>
34 <p class=
"p6"><span class=
"s2"><span class=
"Apple-tab-span"> </span>4, {
</span>"flow has stopped, we don't get here unlike traditional switch implementations"<span class=
"s2"> },
</span></p>
35 <p class=
"p5"><span class=
"s2"><span class=
"Apple-tab-span"> </span></span>// last function is the default
</p>
36 <p class=
"p6"><span class=
"s2"><span class=
"Apple-tab-span"> </span>{
</span>"if the answer wasn't four we would have ended up here, the default"<span class=
"s2"> }
</span></p>
38 <p class=
"p2"><br></p>
40 <p class=
"p2"><br></p>
42 <p class=
"p2"><br></p>
43 <p class=
"p3">switch returns the result of the trueFunc
</p>
44 <p class=
"p2"><br></p>