Made pretty and clarified (#22392)

* fixed indentations, added line breaks
* split the 3 switch case output examples and specified in which situation they would be executed
This commit is contained in:
justingiffard
2018-11-21 16:58:23 +02:00
committed by Tom
parent 81178d2344
commit 5ddb059242

View File

@ -13,11 +13,8 @@ In the first example, when the value of i is 3, the break statement is executed,
int[] array = { 1, 2, 3, 4, 5 }; int[] array = { 1, 2, 3, 4, 5 };
for (int i = 0; i < array.Length; i++) for (int i = 0; i < array.Length; i++)
{ {
if(i == 3) if(i == 3) break;
{ Console.WriteLine("Item on index {0} is {1}", i, array[i]);
break;
}
Console.WriteLine("Item on index {0} is {1}", i, array[i]);
} }
``` ```
@ -37,12 +34,15 @@ switch (exampleVariable)
Console.WriteLine("case 1"); Console.WriteLine("case 1");
Console.WriteLine("This only shows in example 1"); Console.WriteLine("This only shows in example 1");
break; break;
case 2: case 2:
Console.WriteLine("case 2"); Console.WriteLine("case 2");
Console.WriteLine("This only shows in example 2"); Console.WriteLine("This only shows in example 2");
Console.WriteLine("This also only shows in example 2"); Console.WriteLine("This also only shows in example 2");
break; break;
Console.WriteLine("This would not show anywhere, as it is after the break line and before the next case"); Console.WriteLine("This would not show anywhere, as it is after the break line and before the next case");
default: default:
Console.WriteLine("default"); Console.WriteLine("default");
Console.WriteLine("This only shows in the Default Example"); Console.WriteLine("This only shows in the Default Example");
@ -52,15 +52,19 @@ switch (exampleVariable)
``` ```
## Output: ## Output:
#### Executed with `exampleVariable = 1`
``` ```
> case 1 > case 1
> This only shows in example 1 > This only shows in example 1
> ```
#### Executed with `exampleVariable = 2`
```
> case 2 > case 2
> This only shows in example 2 > This only shows in example 2
> This also only shows in example 2 > This also only shows in example 2
> ```
#### Executed with `exampleVariable = 3` or any other number
```
> default > default
> This only shows in the Default Example > This only shows in the Default Example
>
``` ```