Thread: Switch/Case using && != and ||?

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    31

    Switch/Case using && != and ||?

    Can a Switch/Case statement have AND, NOT and OR in it? As in:
    Code:
    switch (a)
    case 1 && c!=4:
    etc.

  2. #2
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    no...why would u need it?

    case:
    break;
    case:
    break;

    etc....for every condition u have a case. I think what your looking for is an if:

    if (1 && c!=4) //psudo code

  3. #3
    Registered User
    Join Date
    Mar 2003
    Posts
    31
    To check to see if a variable equals the input, but isn't already assigned to something else.

  4. #4
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    When i said why would u need it, was because the thing your attempting doesnt call for a switch, or isnt what a switch will do.

  5. #5
    Registered User
    Join Date
    Mar 2003
    Posts
    31
    Ok, I just thought a switch would be easier than many, many, many IF statements. What would be faster? I was thinking, if I stored a bunch of variables in an array, is there any way to compare the input to every variable in the array to see if they match, without using IFs?

  6. #6
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    you dont have to hard code all of the ifs, use a loop...

    Code:
    for(int i=0; i < arrayLength; i++) 
    {
          if(array[i] == input)
               cout << "Yay, array at " << i << "equals input!";
    }

  7. #7
    Registered User
    Join Date
    Mar 2003
    Posts
    31
    Thanks!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Personal Program that is making me go wtf?
    By Submeg in forum C Programming
    Replies: 20
    Last Post: 06-27-2006, 12:13 AM
  2. process killer on a loop
    By Anddos in forum Windows Programming
    Replies: 8
    Last Post: 01-11-2006, 01:50 AM
  3. Replies: 4
    Last Post: 11-23-2003, 07:15 AM
  4. Massive Function Problem
    By Marc Sharp in forum C Programming
    Replies: 10
    Last Post: 11-19-2003, 08:49 PM
  5. Tic Tac Toe Help
    By aresashura in forum C++ Programming
    Replies: 1
    Last Post: 11-21-2001, 12:52 PM