Results 1 to 8 of 8

Thread: Cases

  1. #1
    Join Date
    Feb 2012
    Posts
    170
    Mentioned
    0 Post(s)
    Quoted
    6 Post(s)

    Default Cases

    If I have a case, and I want it to do something if it doesn't run into the integers I gave it, how do I catch everything else?

  2. #2
    Join Date
    Jan 2012
    Posts
    2,568
    Mentioned
    35 Post(s)
    Quoted
    356 Post(s)

    Default

    Have an else statement after the cases. It will be executed if the value doesn't meet any of the cases.

  3. #3
    Join Date
    Feb 2012
    Posts
    170
    Mentioned
    0 Post(s)
    Quoted
    6 Post(s)

    Default

    mmk, like such?

    case findLocation(0) of
    0: begin
    Lave;
    wait(25000 + random(5000));
    end;
    1: begin
    inventory;
    end;
    else: begin
    functionOrWhatNotHere();
    end;
    end;



    would that work? or did I misunderstand the syntax?

  4. #4
    Join Date
    Jan 2012
    Location
    Calgary, AB, Canada
    Posts
    1,819
    Mentioned
    5 Post(s)
    Quoted
    120 Post(s)

    Default

    Basically:

    Simba Code:
    procedure Something;
    begin
      case something of
      //case stuff
      end else //The stuff to do if it doesn't solve the case
    end;
    Current Project: Retired

  5. #5
    Join Date
    Jan 2012
    Posts
    2,568
    Mentioned
    35 Post(s)
    Quoted
    356 Post(s)

    Default

    Quote Originally Posted by Gucci View Post
    Basically:

    Simba Code:
    procedure Something;
    begin
      case something of
      //case stuff
      end else //The stuff to do if it doesn't solve the case
    end;
    It should be encased within the case statement.


    Quote Originally Posted by xdarkshadowx View Post
    mmk, like such?

    case findLocation(0) of
    0: begin
    Lave;
    wait(25000 + random(5000));
    end;
    1: begin
    inventory;
    end;
    else: begin
    functionOrWhatNotHere();
    end;
    end;



    would that work? or did I misunderstand the syntax?
    Simba Code:
    case findLocation(0) of
      0:
      begin
        Lave;
        wait(25000 + random(5000));
      end;

      1:
        inventory;     //begin and end not needed if it's single statement

      else     // ':' is not required after 'else', 'then' etc in Pascal (needed in some other languages such as Python though)
        functionOrWhatNotHere();
    end;

  6. #6
    Join Date
    Jan 2012
    Location
    Calgary, AB, Canada
    Posts
    1,819
    Mentioned
    5 Post(s)
    Quoted
    120 Post(s)

    Default

    Quote Originally Posted by riwu View Post
    It should be encased within the case statement.
    Should work fine there
    Current Project: Retired

  7. #7
    Join Date
    Jan 2012
    Posts
    2,568
    Mentioned
    35 Post(s)
    Quoted
    356 Post(s)

    Default

    Quote Originally Posted by Gucci View Post
    Should work fine there
    Would result in an syntax error.
    You can think case statements as multiple statements of 'else if',
    Quote Originally Posted by Gucci View Post
    Basically:

    Simba Code:
    procedure Something;
    begin
      case something of
      //case stuff
      end else //The stuff to do if it doesn't solve the case
    end;
    Hence the 'end else' here would be like directed at the 'case something of' instead of those 'else if' statements within the case construct

  8. #8
    Join Date
    Jan 2012
    Location
    Calgary, AB, Canada
    Posts
    1,819
    Mentioned
    5 Post(s)
    Quoted
    120 Post(s)

    Default

    Quote Originally Posted by riwu View Post
    Would result in an syntax error.
    You can think case statements as multiple statements of 'else if',

    Hence the 'end else' here would be like directed at the 'case something of' instead of those 'else if' statements within the case construct
    Hmmmm didn't think of it that way
    Current Project: Retired

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •