How to handle user input

The reference does not show String as an expression but it will work.

switch / Reference / Processing.org

Example with a String:

String s = "B1";

//s = "A0";

switch(s) {
  case "A0": 
    println("Alpha");  // Does not execute
    break;
  case "B1": 
    println("Bravo");  // Does not execute
    break;
  default:             // Default executes if the case names
    println("None");   // don't match the switch parameter
    break;
}

The correct way to compare Strings is discussed here:

:)

2 Likes