Author Topic: Switches in C  (Read 1758 times)

0 Members and 1 Guest are viewing this topic.

Offline Dysko

  • 29
    • GolfVictorSpotting.it
Can I insert a switch into another switch cycle in C?
Example:
Code: [Select]
switch(variable1)
   {
   case variable1==1:
      switch(variable2)
      {
      case variable2==2:
         do this;
      default:
         do another thing;
      }
   default:
      do that;
   }
Would switch(variable2) work?
My aircraft spotting website: GolfVictorSpotting.it

 

Offline Ghostavo

  • 210
  • Let it be glue!
    • Skype
    • Steam
    • Twitter
Can I insert a switch into another switch cycle in C?
Example:
Code: [Select]
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
Code: [Select]
case variable# == #: when you are comparing the expression variable# == # to the value of variable# instead of just
Code: [Select]
case #:
P.S.
Also, nitpicking, a switch is not a cycle, it's a flow control statement. :p.
« Last Edit: June 15, 2008, 09:36:40 am by Ghostavo »
"Closing the Box" - a campaign in the making :nervous:

Shrike is a dirty dirty admin, he's the destroyer of souls... oh god, let it be glue...

 

Offline Dysko

  • 29
    • GolfVictorSpotting.it
Yes, you can put switchs inside switchs.
Thank you! :yes:

But more important, why do you use
Code: [Select]
case variable# == #: when you are comparing the expression variable# == # to the value of variable# instead of just
Code: [Select]
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:
My aircraft spotting website: GolfVictorSpotting.it

 

Offline Wanderer

  • Wiki Warrior
  • 211
  • Mostly harmless
Do not meddle in the affairs of coders for they are soggy and hard to light

 

Offline WMCoolmon

  • Purveyor of space crack
  • 213
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.
-C