Switch statement example updated (#37757)
* Switch statement example updated * Update switch-statements.english.md example Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * Update switch-statements.english.md example Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>pull/37764/head
parent
2d647b1638
commit
c4dc0b297f
|
@ -8,20 +8,16 @@ forumTopicId: 18277
|
|||
|
||||
## Description
|
||||
<section id='description'>
|
||||
If you have many options to choose from, use a <code>switch</code> statement. A <code>switch</code> statement tests a value and can have many <code>case</code> statements which define various possible values. Statements are executed from the first matched <code>case</code> value until a <code>break</code> is encountered.
|
||||
Here is a <dfn>pseudocode</dfn> example:
|
||||
If you have many options to choose from, use a <dfn>switch</dfn> statement. A <code>switch</code> statement tests a value and can have many <dfn>case</dfn> statements which define various possible values. Statements are executed from the first matched <code>case</code> value until a <code>break</code> is encountered.
|
||||
Here is an example of a <code>switch</code> statement:
|
||||
|
||||
```js
|
||||
switch(num) {
|
||||
case value1:
|
||||
statement1;
|
||||
switch(lowercaseLetter) {
|
||||
case "a":
|
||||
console.log("A");
|
||||
break;
|
||||
case value2:
|
||||
statement2;
|
||||
break;
|
||||
...
|
||||
case valueN:
|
||||
statementN;
|
||||
case "b":
|
||||
console.log("B");
|
||||
break;
|
||||
}
|
||||
```
|
||||
|
|
Loading…
Reference in New Issue