I am new to java, so want to understand which statement to be used and when ?
Program has a condition where there are three checks needs to be done. I am not clear which statement to go for.
Please help me in understanding the statement usage
I am new to java, so want to understand which statement to be used and when ?
Program has a condition where there are three checks needs to be done. I am not clear which statement to go for.
Please help me in understanding the statement usage
The if
statement is normally used if you just check one or more different conditions that can be connected with logical operators like and
and or
.
//if the color is red or blue
if (color == 'red' | color == 'blue' {
//do something.
}
The switch
statement can be used if you have one condition that has to be handled different, depending on its value.
//do different things depending on the color
switch (color) {
case 'red':
//do something
break;
case 'blue':
//do something else
break;
}