1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
extends ../reference.jade
block documentation
h1 Case
p The case statement is a shorthand for JavaScript's <code>switch</code> statement and takes the following form:
.row(data-control='interactive')
.col-lg-6
+jade
:jadesrc
- var friends = 10
case friends
when 0
p you have no friends
when 1
p you have a friend
default
p you have \#{friends} friends
.col-lg-6
+html
:htmlsrc
<p>you have 10 friends</p>
h2 Case Fall Through
p You can use fall through just like in a select statement in JavaScript
.row(data-control='interactive')
.col-lg-6
+jade
:jadesrc
- var friends = 0
case friends
when 0
when 1
p you have very few friends
default
p you have \#{friends} friends
.col-lg-6
+html
:htmlsrc
<p>you have very few friends</p>
h2 Block Expansion
p Block expansion may also be used:
.row(data-control='interactive')
.col-lg-6
+jade
:jadesrc
- var friends = 1
case friends
when 0: p you have no friends
when 1: p you have a friend
default: p you have \#{friends} friends
.col-lg-6
+html
:htmlsrc
<p>you have a friend</p>
|