1<documentation title="Switch Declarations"> 2 <standard> 3 <![CDATA[ 4 Case statements should be indented 4 spaces from the switch keyword. It should also be followed by a space. Colons in switch declarations should not be preceded by whitespace. Break statements should be indented 4 more spaces from the case statement. There must be a comment when falling through from one case into the next. 5 ]]> 6 </standard> 7 <code_comparison> 8 <code title="Valid: Case statement indented correctly."> 9 <![CDATA[ 10switch ($foo) { 11<em> </em>case 'bar': 12 break; 13} 14 ]]> 15 </code> 16 <code title="Invalid: Case statement not indented 4 spaces."> 17 <![CDATA[ 18switch ($foo) { 19<em></em>case 'bar': 20 break; 21} 22 ]]> 23 </code> 24 </code_comparison> 25 <code_comparison> 26 <code title="Valid: Case statement followed by 1 space."> 27 <![CDATA[ 28switch ($foo) { 29 case<em> </em>'bar': 30 break; 31} 32 ]]> 33 </code> 34 <code title="Invalid: Case statement not followed by 1 space."> 35 <![CDATA[ 36switch ($foo) { 37 case<em></em>'bar': 38 break; 39} 40 ]]> 41 </code> 42 </code_comparison> 43 <code_comparison> 44 <code title="Valid: Colons not prefixed by whitespace."> 45 <![CDATA[ 46switch ($foo) { 47 case 'bar'<em></em>: 48 break; 49 default<em></em>: 50 break; 51} 52 ]]> 53 </code> 54 <code title="Invalid: Colons prefixed by whitespace."> 55 <![CDATA[ 56switch ($foo) { 57 case 'bar'<em> </em>: 58 break; 59 default<em> </em>: 60 break; 61} 62 ]]> 63 </code> 64 </code_comparison> 65 <code_comparison> 66 <code title="Valid: Break statement indented correctly."> 67 <![CDATA[ 68switch ($foo) { 69 case 'bar': 70<em> </em>break; 71} 72 ]]> 73 </code> 74 <code title="Invalid: Break statement not indented 4 spaces."> 75 <![CDATA[ 76switch ($foo) { 77 case 'bar': 78<em> </em>break; 79} 80 ]]> 81 </code> 82 </code_comparison> 83 <code_comparison> 84 <code title="Valid: Comment marking intentional fall-through."> 85 <![CDATA[ 86switch ($foo) { 87 case 'bar': 88 <em>// no break</em> 89 default<em></em>: 90 break; 91} 92 ]]> 93 </code> 94 <code title="Invalid: No comment marking intentional fall-through."> 95 <![CDATA[ 96switch ($foo) { 97 case 'bar': 98 default<em></em>: 99 break; 100} 101 ]]> 102 </code> 103 </code_comparison> 104</documentation> 105