Today #day28 of #100daysofcode, I have completed 2 lessons: 17,18 in module 3 and a practice program in JS. @Sololearn
Conditionals and Loops
The switch Statement
- test multiple conditions.
- to perform different actions based on different conditions.
syntax:
switch (expression) { case n1: statements break; case n2: statements break; default: statements }
In a way: Switch stands for 'if' Case stands for 'else if' Default stands for 'else'
The break Keyword
- to come out of the code execution loop
The default Keyword
- default statement is mandatory this will be executed when there is no match.
- there is no break keyword for default it is the last case which will be executed if there is no match.
Loops
- when you want to execute a block of code repeatedly, you use loops.
- JavaScript hash 3 types of loops they are for loop while loop command do while loop.
The for loop
- syntax: for (statement 1; statement 2; statement 3) { code block to be executed }
- the classic for loop consists of 3 components or statements.
- statement one his optional, statement 2 is optional but you have to put break in the blockcode.
Images:
Conclusion
- The switch Statement
- The for loop
- code
- quiz