The switch keyword
else...if
statements are a great way to have multiple conditions but if number of conditions is very high thanelse...if
would become hectic.So here comes the
switch
keyword which makes it easily readable and writable.The
break
keyword tells the computer to exit the block and not run any more code or check any other cases inside the codeblock.
Example:
Example:
Last updated