Control Flow: Switch
Using "Endswitch". Syntactic Sugar!

You have two ways of creating a switch. First, there's the way we have made all the past exercises:

switch ($i) { 


But we can also make it this way:

switch ($i):


This is called alternative syntax. It exists to provide syntactic sugar

There's no difference when using either the curly brace syntax (first example) or alternative syntax (second example), it only provides readability, thus it's usually used when mixing HTML and PHP code in the same file.


In the editor you have the code of the previous exercise. Make the code use the alternative syntax rather than the curly-brace syntax.

Stuck? Get a hint! Hint
Get live, fast support from Codecademy Advisors when you get stuck. Learn more.

Compare the first and second example. You replace the first curly brace with a : (colon) and the last curly brace with endswitch;

View Preview