| Start |
|---|
| If-Else Statement Programming in general often requires a Lets assume we have method (a.k.a. a function) which takes an int parameter which will represent a score up to 100, and the method will print out a message saying whether we pass or fail. When looking at this method, you may notice this line of code ( For example, if this method was called like this:
However, if the method was called like: In this example, we've said that score should go up to 100, which hasn't been accounted for at all. To account for score not going past 100 or possibly dropping below 0, see the If-Else If-Else Statement example. |
| If-Else If-Else Statement Following on from the If-Else Statement example, it is now time to introduce the In the example from If-Else Statement, the example specified that the score goes up to 100; however there were never any checks against this. To fix this, lets modify the method from If-Else Statement to look like this: All these statements will run in order from the top all the way to the bottom until a condition has been met. In this new update of the method, we've added two new branches to now accommodate for the score going out of bounds. For example, if we now called the method in our code as |
| If statement conditions are standard boolean expressions and values The following statement is exactly equivalent to in other words, the conditions inside the "if" statement just form an ordinary Boolean expression. A common mistake when writing conditional statements is to explicitly compare to This can be rewritten as |
| Switch statements A switch statement allows a variable to be tested for equality against a list of values. Each value is called a case, and the variable being switched on is checked for each switch case. A Syntax is as follows there are sevaral things that have to consider while using the switch statement
Example can be given with the grades wise |
Read Article
https://develop.horje.com/learn/1434/reference