Hard Light Productions Forums
Off-Topic Discussion => Programming => Topic started by: Dysko on June 15, 2008, 09:18:55 am
-
Can I insert a switch into another switch cycle in C?
Example:
switch(variable1)
{
case variable1==1:
switch(variable2)
{
case variable2==2:
do this;
default:
do another thing;
}
default:
do that;
}
Would switch(variable2) work?
-
Can I insert a switch into another switch cycle in C?
Example:
switch(variable1)
{
case variable1==1:
switch(variable2)
{
case variable2==2:
do this;
default:
do another thing;
}
default:
do that;
}
Would switch(variable2) work?
Yes, you can put switchs inside switchs.
But more important, why do you use case variable# == #:
when you are comparing the expression variable# == # to the value of variable# instead of just case #:
P.S.
Also, nitpicking, a switch is not a cycle, it's a flow control statement. :p.
-
Yes, you can put switchs inside switchs.
Thank you! :yes:
But more important, why do you use case variable# == #:
when you are comparing the expression variable# == # to the value of variable# instead of just case #:
Because our programming professor never told us how to use switches, and they are the most effective way to do a part of my programming homework.
I searched on the internet how to use them, and looks like I misunderstood something :nervous:
P.S.
Also, nitpicking, a switch is not a cycle, it's a flow control statement. :P.
Ops. :nervous:
-
Kinda old but still referenced at times.... http://publications.gbdirect.co.uk/c_book/chapter3/flow_control.html
-
The only unusual thing about switches is that you have to use {} if you initialize variables. Otherwise they're just like any other conditional statement.