We know that January, March, May, July, August, October, and December have 31 days, while April, June, September, and November have 30 days. In the above code, month 1 means January, month 2 means February, and so on. In switch, if we don't have a break statement, a matching case falls through until it encounters a break statement, which will be printed with the exception of the default case. The else statement can either be a single statement, or it can even be a block of statements. If it is true, control goes to one block of code, and if it isn’t, then control goes to a different block of code defined in else. The if-else statement allows the programmer to do exactly that with their code. If not a leap year February, the answer is 28. If the month is a leap year, February, the answer is 29. If the month is either April, June, September, and November, the answer is 30. If the month is either of January, March, May, July, August, October, and December, the answer is 31. For example, let's consider a situation where we need to think about the number of days present in each month. In our day-to-day lives, we always decide on things by using if-else. It also explains the similarities and differences between the two of them.This article explains what if-else and switch are.This is what we will cover in this article. It is hence important to understand the benefits and differences between each. While starting with coding, if-else and switch are one of the first things that you learn. Conditional Statements are if, else, else-if and switch. In coding, we use conditional statements for this purpose. For example, if you have already brushed your teeth, you can eat, else you will have to brush your teeth first. Sometimes your actions depend on your decisions. In our day-to-day lives, we make several decisions, from deciding what to wear to deciding what to eat.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |