Smax Smaxović
Smax Smaxović

Reputation: 560

Is possible to have switch in switch?

is this valid C code ? Is possible to have switch in switch ?

switch (i){
 case 1:
  switch(c){
   case 1:
    c = 0;
    break;
   case 3:
    c = 5;
    break;
   }
case 2:
 // another code
}

Upvotes: 0

Views: 248

Answers (3)

masoud
masoud

Reputation: 56519

Yes

C++ § 6.4.2 / 4

Switch statements can be nested; a case or default label is associated with the smallest switch enclosing it.

Upvotes: 4

billz
billz

Reputation: 45450

Yes, to have switch in switch is valid.

§ 6.4.2 The switch statement

4 Switch statements can be nested; a case or default label is associated with the smallest switch enclosing it.

Upvotes: 12

haccks
haccks

Reputation: 106092

Yes. You can have switch within a switch statement.

Upvotes: 2

Related Questions