Answers.Body: <p>Based on the set number, I'm assuming you're using the &quot;Robot Inventor App&quot;, and the scratch-based graphical programming language?</p>
  <p>If that's the case, then I think you're likely to be limited to what Scratch supports, and I don't believe that includes a native switch statement.</p>
  <p>Based on <a href="https://scratch.mit.edu/discuss/topic/20351/" rel="nofollow noreferrer">this thread</a> on the Scratch site, you could try using the <code>broadcast</code> and <code>when I receive</code> blocks to create a <code>switch</code> like statement (assuming you don't need too many of them):</p>
  <p><a href="https://i.sstatic.net/u6t2k.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/u6t2k.png" alt="Simple Switch with Broadcast" /></a></p>
  <p>Basically, you drop the variable into the broadcast message field, and then set up the receive blocks to kick in when the relevant value is seen (I don't own the set, but was able to play around with the App in &quot;streaming&quot; mode to see control flowing through these blocks)</p>
  <p>I've taken this a step further, by using the <code>join</code> block to combine the <code>counter</code> variable with a text string, which would allow for more switch statements in different parts of your program:</p>
  <p><a href="https://i.sstatic.net/rYW9z.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/rYW9z.png" alt="Filtering switches for different paths" /></a></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-10-26T21:05:44.020Z
Answers.Text: Thank for the code. 51515 blocks can do a lot, but obvious limitations. When I was programming in Objective C for the iPhone using xcode I used the case statement when there were more than 2 choices.
Answers.UserDisplayName: BobDaBrick
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-10-27T09:29:29.210Z
Answers.Text: No problem @BobDaBrick, indeed, `switch` statements are ideally the way to go, however they aren't available in scratch.
Answers.UserDisplayName: Zhaph - Ben Duguid
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-10-25T21:26:46.120Z
Answers.LastActivityDate: 2021-10-25T21:26:46.120Z
Answers.UserDisplayName: Zhaph - Ben Duguid
Body: <p>Is there a way to act on multiple values for a variable? For example, <code>x</code> may be 1, 2, or 3. If then else allows for 2 conditions. Multiple &quot;ifs&quot; work, but is cumbersome.</p>
  <p>Ideally I'd like a switch statement, such as:</p>
  <pre><code>switch (x) {
    case 1:
      Block1;
      break;
    case 2:
      Block2;
      break;
    case 3:
      Block3;
      break;
    default:
      break;
  }
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-10-24T04:50:59.940Z
Comments.Text: Do you mean with microPython, or the LabView-derived graphical system? Either way, the keyword you seek is **or**. See, for instance, <https://www.youtube.com/watch?v=mFYmjKX00pk>
Comments.UserDisplayName: RSchulz
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-10-25T15:21:08.480Z
Comments.Text: Something like this:switch( expression )
  {
   case value-1:
     Block-1;
     Break;
   case value-2:
     Block-2;
     Break;
   case value-n:
     Block-n;
     Break;
   default:
     Block-1;
     Break;
  }
  Statement-x;
Comments.UserDisplayName: BobDaBrick
Tags: <mindstorms><programming>
Title: Mindstorm 51515 If then else alternative - like a switch statement
UserDisplayName: BobDaBrick
ThreadText: # Mindstorm 51515 If then else alternative - like a switch statement
  
  (Asked by: username_0 on 2021-10-23)
  
  Is there a way to act on multiple values for a variable? For example, `x` may be 1, 2, or 3. If then else allows for 2 conditions. Multiple "ifs" work, but is cumbersome.
  
  Ideally I'd like a switch statement, such as:
  
  ```
  switch (x) {
    case 1:
      Block1;
      break;
    case 2:
      Block2;
      break;
    case 3:
      Block3;
      break;
    default:
      break;
  }
  
  ```
  
  **Tags:** mindstorms, programming
  
  > **Comments:**
  > **username_1**: Do you mean with microPython, or the LabView-derived graphical system? Either way, the keyword you seek is **or**. See, for instance, <https://www.youtube.com/watch?v=mFYmjKX00pk>  
  > **username_0**: Something like this:switch( expression ) {  case value-1:    Block-1;    Break;  case value-2:    Block-2;    Break;  case value-n:    Block-n;    Break;  default:    Block-1;    Break; } Statement-x;  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2021-10-25. Score: 4
  
  Based on the set number, I'm assuming you're using the "Robot Inventor App", and the scratch-based graphical programming language?
  
  If that's the case, then I think you're likely to be limited to what Scratch supports, and I don't believe that includes a native switch statement.
  
  Based on [this thread](https://scratch.mit.edu/discuss/topic/20351/) on the Scratch site, you could try using the `broadcast` and `when I receive` blocks to create a `switch` like statement (assuming you don't need too many of them):
  
  [![Simple Switch with Broadcast](https://i.sstatic.net/u6t2k.png)](https://i.sstatic.net/u6t2k.png)
  
  Basically, you drop the variable into the broadcast message field, and then set up the receive blocks to kick in when the relevant value is seen (I don't own the set, but was able to play around with the App in "streaming" mode to see control flowing through these blocks)
  
  I've taken this a step further, by using the `join` block to combine the `counter` variable with a text string, which would allow for more switch statements in different parts of your program:
  
  [![Filtering switches for different paths](https://i.sstatic.net/rYW9z.png)](https://i.sstatic.net/rYW9z.png)
  
  > **Comments:**
  > **username_0**: Thank for the code. 51515 blocks can do a lot, but obvious limitations. When I was programming in Objective C for the iPhone using xcode I used the case statement when there were more than 2 choices.  
  > **username_2**: No problem @username_0, indeed, `switch` statements are ideally the way to go, however they aren't available in scratch.  
  
  ---
  
  