Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Question With Switch Statements

$
0
0
Hello, so for my project i'm using a switch statement to return int values. So like so...
switch(x) {
	case 1: 
		return 1;
	case 2:
		return 3;
	default:
		return 9;
}

How me code works is it sets a value for x to either 1 or 2, choosing the correct case and returning the correct value, however, if a certain condition is met, I want it to return the default value, so lets say the condition is as follows...
x = 1;
y = 2;

if(y == 2) {
	//set value to default
}

So because y is 2. x should be returned as 9. Any help is greatly appreciated, thanks!

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>