Switch on int is not working

Hi! I have this code that is not working (gives unexpected results/ crashes)

switch (myCurrentSelection)
		{
		case 0: myGoToStory();
		case 1: myGoToMap();
		case 2: myGotoCollection();
		case 3: myGoToAchievements();
		case 4: myLibroOut();
		case 5: myExit();
		}

but I replace with this code and works perfect (basically is the same but i think is less efficient)

if (myCurrentSelection == 0) myGoToStory();
if (myCurrentSelection == 1) myGoToMap();
if (myCurrentSelection == 2) myGotoCollection();
if (myCurrentSelection == 3) myGoToAchievements();
if (myCurrentSelection == 4) myLibroOut();
if (myCurrentSelection == 5) myExit();

Any idea? Thanks!

why not use an enum instead of an integer? and u also need an break statement after every case execution otherwise all of the functions will be called.

1 Like

Hey! thanks for your reply :slight_smile:

you’re right. I just forgot to use the break statement
and yeah I should get used to use enums instead.