0

which is better if/else or case

i totally didnt do this for xp

4th Nov 2016, 1:15 AM
julio
6 odpowiedzi
+ 2
it depends on the options you have if therer just few options if else can be used but for more than one option case if used. yes diwas told it right. to use if else in more than three options we can use nested if and else which will make the small situation very big. however nested if else have its own significance and sometimes in case of analysing value of more vars can be preferred so it depends on situation
4th Nov 2016, 1:31 AM
Sandeep Chatterjee
+ 2
Well they all have similar functions, but comparison the 'If' statement condition expression evaluates the code inside of if true, while the 'else' statement is house when the statement in the 'if' turn false, while switch statement test a variable for equality to a list of values. Each value is represent as 'case'.
4th Nov 2016, 1:40 AM
Abdelaziz Abubaker
Abdelaziz Abubaker - avatar
+ 1
if u have have multiple condition, then use "switch case" else "if/else" is better. ex: switch case is good for condition like days of a week and if/else is good for condition like my first sentence.
4th Nov 2016, 1:36 AM
Diwas
Diwas - avatar
+ 1
Usually, if you have >= 3 values, use switch / case. However, switch / case cannot handle operators like >, <, >= and so on — it only compares using ==. If you need to use >=, < and so on, use if / else.
4th Nov 2016, 6:30 AM
Samuel Neo
Samuel Neo - avatar
+ 1
it's depends upon what you need let's say that u need if X==y I don't think you can do it in switch/case but there are some things that are easier o n switch
12th Nov 2016, 2:36 PM
Nes Denon
Nes Denon - avatar
0
wow. the question I forgot the most had the most answers.
2nd Jan 2017, 6:26 AM
julio