tezvyn:

How does Swift's switch differ from C's switch?

Source: interviewbeginner

WHAT IT TESTS: understanding Swift's safer control flow. OUTLINE: switches must be exhaustive, there is no implicit fallthrough between cases, and cases can match ranges, tuples, and bind values.

WHAT IT TESTS: whether you know how Swift redesigned switch for safety and expressiveness. ANSWER OUTLINE: Swift switches must be exhaustive, so the compiler forces a default or full case coverage; there is no implicit fallthrough, so each matched case runs only its own block and no trailing break is needed; cases can match ranges, tuples, enums, and use where clauses and value binding. RED FLAG: claiming you must write break to stop fallthrough, or not knowing switch can pattern-match beyond simple integer constants.

Read the original → interview

Get five bites like this every day.

Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.

How does Swift's switch differ from C's switch? · Tezvyn