0

Hi,

I tried searching but I don't know how exactly to describe my question in 2-3 words so I didn't find anything.
Is it possible to do something like this?Just to get the idea... I know it doesn't work:

switch(c){
	case '1':{ (...) ; break;}
	case '2':{ (...) ; break;}
	case '3':{ (...) ; break;}
	if(f){
		case '4':{ (...) ; break;}
		case '5':{ (...) ; break;}
		case '6':{ (...) ; break;}
	}
}

I can always do it this way:

if(f){
	switch(c){
		case '1':{ (...) ; break;}
		case '2':{ (...) ; break;}
		case '3':{ (...) ; break;}
		case '4':{ (...) ; break;}
		case '5':{ (...) ; break;}
		case '6':{ (...) ; break;}
	}
}
else{
	switch(c){
		case '1':{ (...) ; break;}
		case '2':{ (...) ; break;}
		case '3':{ (...) ; break;}
	}
}

Or put the if check in cases 4,5,6...
Isn't there anything simpler and better to do?

3
Contributors
2
Replies
4
Views
6 Years
Discussion Span
Last Post by L7Sqr
0
switch(c){
		case '1':{ (...) ; break;}
		case '2':{ (...) ; break;}
		case '3':{ (...) ; break;}
	}
	if(f){
		switch(c){
			case '4':{ (...) ; break;}
			case '5':{ (...) ; break;}
			case '6':{ (...) ; break;}
		}
	}
0

You could always take advantage of the short-circuit operators.

switch (argc) {
        case 1: { printf("1\n"); break; }
        case 2: { printf("2\n"); break; }
        case 3: { printf("3\n"); break; }
        case 4: { (f) && printf("4\n"); break; }
        case 5: { (f) && printf("5\n"); break; }
        case 6: { (f) && printf("6\n"); break; }
    }
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.