“Syntactic Sugar”

The switch statement does exactly what a bunch of if-else statements would do, but in a more concise way. In programming, you can often perform the same task in several different ways. When a programming language gives you an easy, concise way of performing a specific type of task, this is often called syntactic sugar (perhaps because the concise syntax “tastes” better?). There is almost always another way to write whatever code you have written. The alternative might execute faster, might be easier to understand, might be more secure, or might just be different. Regardless, your way is probably not the only way, so keep an open mind.

for

Another way to control your program’s flow is to use a loop. A loop executes a given set ...

Get Learning to Program now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.