✏️ The if-statement causes a branch in the flow of a program's execution and the else-if idiom is used for multi-branches.
What happens when all branches depend on the same value of the expression?
That is when the switch statement comes in.
✏️ A switch statement is a type of selection control mechanism used to allow the value of a variable or expression to change the control flow of program execution.
Flow Diagram.
✏️ A switch statement starts with a variable called the switch vale. Each case indicates a possible value for this variable and the code that run if the variable matches the value.
✏️ Basic syntax.
✏️ Example.
n here is the switch value. if the value entered == 1,
case 1 is executed. if n == 2, then case 3 is executed.
If none matches the cases, then the default case will be executed.
• • •
Missing some Tweet in this thread? You can try to
force a refresh
MY THREADS OF THE YEAR.
Wrapping up my 2021 with the best threads. I join tech twitter just 2 months ago and these major threads have helped shape me.
They may not be the best of the best but to me, these people and their amazing threads are the real MVP of my development
🧵🧵🧵
💥 2 months ago I had no idea about web development.
I was depressed trying to figure my life out until I chanced upon this thread.
Although I'm into front-end this is the first thread I read on tech twitter and things haven't been the same.