how many braches can i create using if statement?? is it limited??
A:
No, it is not limited except by the storage capacity on your development system.
Alexander Gessler
2010-06-17 19:29:30
I think that strongly depends on the compiler in question ...
Joey
2010-06-17 19:52:32
He did not say that he intends to compile his code, actually. I can put as many branches in my files as I want, the only limiting factor will be the storage capacity plus file system constraints :-)
Alexander Gessler
2010-06-17 20:48:17
+1
A:
An IF
statement always has exactly two branches: one where the condition is FALSE
and one where the condition is TRUE
. A branching construct that has more than two branches is usually called CASE
or SWITCH
. In Pascal, it's CASE
.
Jörg W Mittag
2010-06-17 19:52:54
Of course, you can always nest your control structures, limited only by your ability to copy-and-paste, and the compilers memory limits.
Craig Trader
2010-06-17 21:28:15
A:
Always think towards a State/Strategy pattern before making a ton of branches on logic. Not sure your language of choice so I cant really help with concrete implementation, but you should be able to refactor any switch case or if comparable into a Key hooked to the correct value, and pull out the object/method/variable needed based on your key.
Gnostus
2010-06-17 19:56:50