# How do I use an enum with a switch statement?

**URL:** <https://forums.unrealengine.com/t/how-do-i-use-an-enum-with-a-switch-statement/430262>\
**Category:** Platform & Builds\
**Tags:** Switch, ENUM, unreal-engine, question, CPP\
**Created:** [July 26, 2018, 1:55am UTC](https://forums.unrealengine.com/t/how-do-i-use-an-enum-with-a-switch-statement/430262 "2018-07-26T01:55:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Slavical](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Slavical](https://forums.unrealengine.com/u/Slavical)\
**Post date:** [July 26, 2018, 1:55am UTC](https://forums.unrealengine.com/t/how-do-i-use-an-enum-with-a-switch-statement/430262/1 "2018-07-26T01:55:02Z")

</div>

Like the title asks, how do I use a switch statement as an enum for the condition?

---

<div class="post-metadata">

**Author:** ![Veseliy](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/veseliy/32/600830_2.png) [@Veseliy](https://forums.unrealengine.com/u/Veseliy)\
**Post date:** [July 26, 2018, 5:44am UTC](https://forums.unrealengine.com/t/how-do-i-use-an-enum-with-a-switch-statement/430262/2 "2018-07-26T05:44:22Z")

</div>

Enum is represented as integer numbers, so you can just use 0,1,2,3… for case conditions.

> enum class EVictoryEnum : uint8

or you can use

> enum::value

as condition

Here is more detailed explanation:  
[https://wiki.unrealengine.com/Enums\_For\_Both\_C%2B%2B\_and\_BP](https://wiki.unrealengine.com/Enums_For_Both_C%2B%2B_and_BP)

Hope it helps.

Regards,  
Alex.

---

<div class="post-metadata">

**Author:** ![Slavical](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Slavical](https://forums.unrealengine.com/u/Slavical)\
**Post date:** [July 26, 2018, 2:24pm UTC](https://forums.unrealengine.com/t/how-do-i-use-an-enum-with-a-switch-statement/430262/3 "2018-07-26T14:24:40Z")

</div>

I was looking at that article before, when I was structuring out my enum; but it doesn’t explicitly say how to use it within a switch (at least not to my current knowledge).

So here’s my pseudo code and let me know if it seems right (I won’t be able to test it until after work).

Header file:

```
UENUM(BlueprintType)
enum class EStance : uint8
{
        S_Standing UMETA(DisplayName = "Standing"),
        S_Crouching UMETA(DisplayName = "Crouching")
};

UCLASS()
class YourClass : public YourSuperClass
{
	GENERATED_UCLASS_BODY()
 
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=Enum)
	EStance Stance;
 
	//Rest of Class Code
};

```

CPP File

```
switch (Stance)
{
case 0:
// Player is standing
break;

case 1:
// Player is crouching
break;
}
```

---

<div class="post-metadata">

**Author:** ![Veseliy](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/veseliy/32/600830_2.png) [@Veseliy](https://forums.unrealengine.com/u/Veseliy)\
**Post date:** [July 26, 2018, 3:09pm UTC](https://forums.unrealengine.com/t/how-do-i-use-an-enum-with-a-switch-statement/430262/4 "2018-07-26T15:09:08Z")

</div>

Seems right to me.

or, you can use:

```
switch (Stance)
{
case EStance::S_Standing: ...
break;
case EStance::S_Crouching: ...
break;
}

```

Regards,  
Alex.

---

<div class="post-metadata">

**Author:** ![CyKrome](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@CyKrome](https://forums.unrealengine.com/u/CyKrome)\
**Post date:** [January 2, 2023, 8:53am UTC](https://forums.unrealengine.com/t/how-do-i-use-an-enum-with-a-switch-statement/430262/5 "2023-01-02T08:53:05Z")

</div>

> [@Slavical](#):
>
> `EStance Stance`

When I write it like this is shows ‘’‘Duplicate Name’‘’
