Post

CodeRed
CodeRed@CodeRed_dev·
The ultimate programmer question. If statements or switch statements.
English
124
2
137
23.3K
eno Rogue
eno Rogue@ZenoRogue·
@CodeRed_dev You forgot OOP (virtual functions in place of if/switch)
English
1
0
4
211
pixelrogueart
pixelrogueart@pixelrogueart·
@CodeRed_dev I love switch statements, they look so nice and organized 😂
English
0
0
6
414
Gustav 🌐
Gustav 🌐@GustavThoft·
@CodeRed_dev that's like asking if you should use a rake or bush trimmer for garden work. you use 'if' either if there's only one arm, you're checking multiple different things, or when there are multiple arms with different checks. You use switch one variable is checked for many conditions.
English
0
0
1
26
Michal Rotter
Michal Rotter@TheRotterik·
@CodeRed_dev Both. 'Switch' for enums, multiple choices or conditions; 'If' for single condition. I'm not using 'Switch' to check whether toggle is on or off, and I don't use 'If' to check what state my character is in.
English
0
0
1
83
Argore
Argore@Argore_·
@CodeRed_dev If there's less than like 4 paths, if statement. Anything more and it's a switch case
English
0
0
1
9
Johnathan Mueller
Johnathan Mueller@JohnMuellerTMG·
@CodeRed_dev I voted "if" because I tend to use them more often, but "switch" is also good for certain features too
English
0
0
1
88
Xalkomak Does 3D
Xalkomak Does 3D@XalkomakCreates·
@CodeRed_dev When there is only one condition that needs to be checked (for example, if an object belongs to a certain class), I go for switch cases. In case of multiple conditional checks within the same line, the traditional if-else is what I follow.
English
0
0
1
53
Trying to Code
Trying to Code@TryingtwoCode·
@CodeRed_dev string weaponType = "Throwable Gernade" if(weaponType == "Throwable Gernade"){ //do throwable gernade things } if(weaponType == "Normal Gernade"){ //do normal gernade things } if(weaponType == "Axe Murderer Gernade"){ //do normal axe murderer gernade things } //etc.
English
0
0
1
29
Chris Gallaty
Chris Gallaty@cgallaty·
@CodeRed_dev It's not an either or question. Some cases lend themselves to switch, others require an if or two.
English
0
0
1
422
Paylaş