From f0b29bcb281f18d99b31df7679498baed774eaf4 Mon Sep 17 00:00:00 2001 From: "THIRUMURUGAN.R" <43858889+rthirumurugan2000@users.noreply.github.com> Date: Thu, 28 Mar 2019 17:24:26 +0530 Subject: [PATCH] Add some info to switch in C++ (#31092) --- guide/english/cplusplus/switch-statements/index.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/guide/english/cplusplus/switch-statements/index.md b/guide/english/cplusplus/switch-statements/index.md index f4b69ccc809..e36d17dac66 100644 --- a/guide/english/cplusplus/switch-statements/index.md +++ b/guide/english/cplusplus/switch-statements/index.md @@ -20,7 +20,7 @@ switch(expression) { The following rules apply to a switch statement − -The expression used in a switch statement must have an integral or enumerated type, or be of a class type in which the class has a single conversion function to an integral or enumerated type. +The expression used in a switch statement must have an integral or enumerated type(int,char,enum), or be of a class type in which the class has a single conversion function to an integral or enumerated type. You can have any number of case statements within a switch. Each case is followed by the value to be compared to and a colon. @@ -32,7 +32,10 @@ When a break statement is reached, the switch terminates, and the flow of contro Not every case needs to contain a break. If no break appears, the flow of control will fall through to subsequent cases until a break is reached. -A switch statement can have an optional default case, which must appear at the end of the switch. The default case can be used for performing a task when none of the cases is true. No break is needed in the default case. +A switch statement can have an optional default case, which must appear at the end of the switch. The default case can be used for performing a task when none of the cases is true. No break is needed in the default case. The position of default block doesn't matter, it is automatically executed if no match is found. + +Two case labels cannot have the same value. + Example: ```C++