---
title: "Switch Statements"
content_type: tutorial
url: "https://learn.unity.com/course/beginner-scripting/tutorial/switch-statements?language=en"
language: en
container_type: course
container_title: "Beginner Scripting"
container_url: "https://learn.unity.com/course/beginner-scripting.md?language=en&version=2019.3"
standalone_markdown_url: "https://learn.unity.com/tutorial/switch-statements.md?language=en&version=2019.3"
previous_title: "Enumerations"
previous_url: "https://learn.unity.com/course/beginner-scripting/tutorial/enumerations?language=en&version=2019.3"
previous_markdown_url: "https://learn.unity.com/course/beginner-scripting/tutorial/enumerations.md?language=en&version=2019.3"
difficulty: beginner
duration_minutes: 5
unity_version:
  - "2019.3"
  - "2019.2"
  - "2019.1"
  - "2018.4"
  - "2018.3"
  - "2018.2"
  - "2018.1"
  - "2017.4"
  - "2017.3"
  - "2017.2"
  - "2017.1"
  - "5.x"
  - "4.x"
supported_unity_versions:
  - name: "2019.3"
    url: "https://learn.unity.com/course/beginner-scripting/tutorial/switch-statements.md?language=en&version=2019.3"
  - name: "2019.2"
    url: "https://learn.unity.com/course/beginner-scripting/tutorial/switch-statements.md?language=en&version=2019.2"
  - name: "2019.1"
    url: "https://learn.unity.com/course/beginner-scripting/tutorial/switch-statements.md?language=en&version=2019.1"
  - name: "2018.4"
    url: "https://learn.unity.com/course/beginner-scripting/tutorial/switch-statements.md?language=en&version=2018.4"
  - name: "2018.3"
    url: "https://learn.unity.com/course/beginner-scripting/tutorial/switch-statements.md?language=en&version=2018.3"
  - name: "2018.2"
    url: "https://learn.unity.com/course/beginner-scripting/tutorial/switch-statements.md?language=en&version=2018.2"
  - name: "2018.1"
    url: "https://learn.unity.com/course/beginner-scripting/tutorial/switch-statements.md?language=en&version=2018.1"
  - name: "2017.4"
    url: "https://learn.unity.com/course/beginner-scripting/tutorial/switch-statements.md?language=en&version=2017.4"
  - name: "2017.3"
    url: "https://learn.unity.com/course/beginner-scripting/tutorial/switch-statements.md?language=en&version=2017.3"
  - name: "2017.2"
    url: "https://learn.unity.com/course/beginner-scripting/tutorial/switch-statements.md?language=en&version=2017.2"
  - name: "2017.1"
    url: "https://learn.unity.com/course/beginner-scripting/tutorial/switch-statements.md?language=en&version=2017.1"
  - name: "5.x"
    url: "https://learn.unity.com/course/beginner-scripting/tutorial/switch-statements.md?language=en&version=5.x"
  - name: "4.x"
    url: "https://learn.unity.com/course/beginner-scripting/tutorial/switch-statements.md?language=en&version=4.x"
last_updated: "2026-08-04T14:21:59.000Z"
---

# Switch Statements

Learn to write and use C# switch statements to compare one value against multiple constants in your Unity scripts.

Switch statements act like streamline conditionals. They are useful for when you want to compare a single variable against a series of constants. In this video you will learn how to write and use switch statements.

This tutorial is included in the [Beginner Scripting project](https://learn.unity.com/project/beginner-gameplay-scripting).

Previous: [Enumerations](https://learn.unity.com/tutorial/enumerations?projectId=5c8920b4edbc2a113b6bc26a)

Next: This is the final tutorial in the project.

## Switch Statements

[Video](https://connect-mediagw.unity.com/h1/20220104/videos/e3969030-bd4a-404c-8efa-f58fea8e3435_U_Beginner_26_SwitchStatements.mp4)

## **ConversationScript**

```csharp
using UnityEngine;
using System.Collections;

public class ConversationScript : MonoBehaviour 
{
    public int intelligence = 5;
    
    
    void Greet()
    {
        switch (intelligence)
        {
        case 5:
            print ("Why hello there good sir! Let me teach you about Trigonometry!");
            break;
        case 4:
            print ("Hello and good day!");
            break;
        case 3:
            print ("Whadya want?");
            break;
        case 2:
            print ("Grog SMASH!");
            break;
        case 1:
            print ("Ulg, glib, Pblblblblb");
            break;
        default:
            print ("Incorrect intelligence level.");
            break;
        }
    }
}
```
