Thread: multiple cases

  1. #1
    Unregistered
    Guest

    Question multiple cases

    How would I check for multiple values in a switch case? This is for a function that increments to the next frame of an animation, it takes in two variables: the current frame (Position) and whether this is a left foot forward or right foot forward step (Footing). I've listed the code for what I'm trying to do:

    switch (Position)
    {
    case 0:
    if (Footing==0)
    {
    return 1;
    }
    else if (Footing==1)
    {
    return 6;
    }
    break;
    case >=1 && <=4 //this is where I'm not sure of the syntax
    if (Footing==0)
    {
    return Position + 1;
    }
    else if (Footing==1)
    {
    return Position - 1;
    }
    break;
    }

    In the case that Position is 1 to 4, I check the current step and then increment or decrement accordingly. Thanks in advance for any help you can give.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > case >=1 && <=4 //this is where I'm not sure of the syntax
    No you can't do that

    Just list them all as
    case 1:
    case 2:
    case 3:
    case 4:
    // case 1 to 4 code here
    break;

  3. #3
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065

    Exclamation Thanks

    Thanks a ton, Salem. I'm making the transition from VB to C/C++ so I keep getting stuck where I know what I want to logically but I don't know the proper C/C++ syntax. Thanks again.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 06-08-2009, 03:03 PM
  2. How to handle multiple cases which use common code?
    By tmaxx in forum C Programming
    Replies: 3
    Last Post: 10-03-2008, 07:42 AM
  3. Linker errors - Multiple Source files
    By nkhambal in forum C Programming
    Replies: 3
    Last Post: 04-24-2005, 02:41 AM
  4. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  5. Replies: 1
    Last Post: 05-01-2003, 02:52 PM