Editing Switch 1 You are editing an old version of this page. If you save it, any changes made since this version will be lost. You are editing an old version of this page. If you save it, any changes made since this version will be lost. You are not logged in. The rich text editor does not work with JavaScript switched off. Please either enable it in your browser options, or visit your preferences to switch to the old MediaWiki editor A '''switch''' statement is FiM++'s way of compressing code for the programmer and making if-then-else-if-then chains more readable by the reader. == Related [[Phrases]] == * {{code|keyword|In regards to}} * {{code|keyword|On the}} ** {{code|keyword|hoof}} ** {{code|keyword|nd hoof}} ** {{code|keyword|rd hoof}} ** {{code|keyword|st hoof}} ** {{code|keyword|th hoof}} * {{code|keyword|If all else fails}} * {{code|keyword|That's what I did}} == [[FDS]] == * Declaration: {{codeblock|{{code|keyword|In regards to}}{{code|whitespace| }}{{tag|value|number}}{{tag|punctuation}}}} ** Exactly one * Case: {{codeblock|{{code|keyword|On the}}{{code|whitespace| }}{{tag|value|number constant}}[{{code|keyword|nd hoof}}/{{code|keyword|rd hoof}}/{{code|keyword|st hoof}}/{{code|keyword|th hoof}}]{{tag|punctuation}}}} ** Optional ** Selected when the value passed to the declaration is the same as the value in the case. ** The numerical value MUST be a [[literal]] number or constant. Variables and [[method]] returns are not allowed. *** The value must be unique from all others in the switch ** Can be followed by any runnable code. * Default case: {{codeblock|{{code|keyword|If all else fails}}{{tag|punctuation}}}} ** Up to one ** Selected when no other case is selected ** Can be followed by any runnable code. * Ending: {{codeblock|{{code|keyword|That's what I did}}{{tag|punctuation}}}} ** Exactly one == Examples == * {{codeblock|{{code|keyword|In regards to}}{{code|whitespace| }}{{code|variable|Pinkie’s Tail}}{{code|punctuation|:}}{{code|whitespace|<BR />}}{{code|keyword|On the}}{{code|whitespace| }}{{code|literal|1}}{{code|keyword|st hoof}}{{code|puntuation|.}}{{code|puntuation|.}}{{code|puntuation|.}}{{code|whitespace|<BR />}}{{code|keyword|I said}}{{code|whitespace| }}{{code|literal|“That’s impossible!”}}{{code|puntuation|.}}{{code|whitespace|<BR />}}{{code|keyword|On the}}{{code|whitespace| }}{{code|literal|2}}{{code|keyword|nd hoof}}{{code|puntuation|.}}{{code|puntuation|.}}{{code|puntuation|.}}{{code|whitespace|<BR />}}{{code|keyword|I said}}{{code|whitespace| }}{{code|literal|“There must be a scientific explanation”}}{{code|puntuation|.}}{{code|whitespace|<BR />}}{{code|keyword|On the}}{{code|whitespace| }}{{code|literal|3}}{{code|keyword|rd hoof}}{{code|puntuation|.}}{{code|puntuation|.}}{{code|puntuation|.}}{{code|whitespace|<BR />}}{{code|keyword|I said}}{{code|whitespace| }}{{code|literal|“There must be an explanation”}}{{code|puntuation|.}}{{code|whitespace|<BR />}}{{code|keyword|On the}}{{code|whitespace| }}{{code|literal|4}}{{code|keyword|th hoof}}{{code|puntuation|.}}{{code|puntuation|.}}{{code|puntuation|.}}{{code|whitespace|<BR />}}{{code|keyword|I said}}{{code|whitespace| }}{{code|literal|“Why does this happen?!”}}{{code|puntuation|.}}{{code|whitespace|<BR />}}{{code|keyword|I would}}{{code|whitespace| }}{{code|method|flail}}{{code|puntuation|.}}{{code|whitespace|<BR />}}{{code|keyword|If all else fails}}{{code|puntuation|.}}{{code|puntuation|.}}{{code|puntuation|.}}{{code|whitespace|<BR />}}{{code|keyword|I said}}{{code|whitespace| }}{{code|literal|“She’s just being Pinkie Pie.”}}{{code|puntuation|.}}{{code|whitespace|<BR />}}{{code|keyword|That’s what I did}}{{code|puntuation|.}} }} *{{codeblock|{{code|keyword|In regards to}}{{code|whitespace| }}{{code|method|being silly}}{{code|punctuation|:}}{{code|whitespace| }}{{code|keyword|That's what I did}}{{code|punctuation|.}}}} ** A switch does not need a body. This line would only be written for human-readability and should not be compiled. *{{codeblock|{{code|keyword|Did you know that}}{{code|whitespace| }}{{code|variable|the best Princess}}{{code|whitespace| }}{{code|keyword|is}}{{code|whitespace| }}{{code|type|number}}{{code|whitespace| }}{{code|literal|1}}{{code|punctuation|?}}{{code|whitespace|<BR />}}{{code|keyword|Did you know that}}{{code|whitespace| }}{{code|constant|Luna}}{{code|whitespace| }}{{code|keyword|always is}}{{code|whitespace| }}{{code|type|number}}{{code|whitespace| }}{{code|literal|1}}{{code|punctuation|?}}{{code|whitespace|<BR />}}{{code|keyword|Did you know that}}{{code|whitespace| }}{{code|constant|Celestia}}{{code|whitespace| }}{{code|keyword|always is}}{{code|whitespace| }}{{code|type|number}}{{code|whitespace| }}{{code|literal|2}}{{code|punctuation|?}}{{code|whitespace|<BR />}}{{code|keyword|In regards to}}{{code|whitespace| }}{{code|variable|the best Princess}}{{code|punctuation|:}}{{code|whitespace|<BR />}}{{code|keyword|On the}}{{code|whitespace| }}{{code|constant|Luna}}{{code|whitespace| }}{{code|keyword|hoof}}{{code|puntuation|.}}{{code|puntuation|.}}{{code|puntuation|.}}{{code|whitespace|<BR />}}{{code|keyword|I said}}{{code|whitespace| }}{{code|literal|“That’s right!”}}{{code|puntuation|.}}{{code|whitespace|<BR />}}{{code|keyword|On the}}{{code|whitespace| }}{{code|constant|Celestia}}{{code|whitespace| }}{{code|keyword|hoof}}{{code|puntuation|.}}{{code|puntuation|.}}{{code|puntuation|.}}{{code|whitespace|<BR />}}{{code|keyword|I said}}{{code|whitespace| }}{{code|literal|“Something's wrong, here...”}}{{code|puntuation|.}}{{code|whitespace|<BR />}}{{code|keyword|That's what I did}}{{code|punctuation|.}}}} == See Also == * [[Conditional Statements]] * [[If]] * [[Else]] {{Navbox/Phrases}} Loading editor Below are some commonly used wiki markup codes. Simply click on what you want to use and it will appear in the edit box above. Insert: – — … ° ≈ ≠ ≤ ≥ ± − × ÷ ← → · § Sign your username: ~~~~ Wiki markup: {{}} | [] [[]] [[Category:]] #REDIRECT [[]] <s></s> <sup></sup> <sub></sub> <code></code> <blockquote></blockquote> <ref></ref> {{Reflist}} <references/> <includeonly></includeonly> <noinclude></noinclude> {{DEFAULTSORT:}} <nowiki></nowiki> <!-- --> <span class="plainlinks"></span> Symbols: ~ | ¡ ¿ † ‡ ↔ ↑ ↓ • ¶ # ¹ ² ³ ½ ⅓ ⅔ ¼ ¾ ⅛ ⅜ ⅝ ⅞ ∞ ‘ “ ’ ” «» ¤ ₳ ฿ ₵ ¢ ₡ ₢ $ ₫ ₯ € ₠ ₣ ƒ ₴ ₭ ₤ ℳ ₥ ₦ № ₧ ₰ £ ៛ ₨ ₪ ৳ ₮ ₩ ¥ ♠ ♣ ♥ ♦ View this template This field is a spam trap. DO NOT fill it in! Edit summary Preview Mobile Desktop Show changes