नमस्कार मित्रांनो Technical Sham च्या एका नवीन आणि इंटरेस्टिंग ब्लॉग मध्ये तुमचे सहर्ष स्वागत आहे.
हॅलो फ्रेंड्स या ब्लॉगमध्ये तुम्हाला Java प्रोग्रामिंग बद्दल शिकायला भेटेल तसेच माझे YouTube चैनल आहे, त्यामध्ये मी व्हिडिओ एडिटिंग करतो त्यासाठी जे काही मटेरियल आहे ते तुम्हाला या साईट वरती मिळून जाईल खाली डाउनलोड ऑप्शन मिळेल स्क्रोल करा तिथून तुम्ही हे सर्व मटेरियल डाउनलोड करून घ्या तर जर तुम्ही Programmers/Codder असाल तर फक्त प्रोग्रामिंग Content कडे लक्ष द्या आणि जर एडिटर असाल तर खाली मटेरियल दिला असेल मटरेल दिला आहे तिथून तुम्ही म्हटले डाऊनलोड करा.
Scroll Now 👇🏻👇🏻
Nested ifs :
A nested if is an if statement that is the target of another if or else. Nested ifs are very common in programming. When you nest ifs, the main thing to remember is that an else statement always refers to the nearest if statement that is within the same block as the else and that is not already associated with an else. Here is an example:
As the comments indicate, the final else is not associated with if(j<20) because it is not in the same block (even though it is the nearest if without an else). Rather, the final else is associated with if(i==10). The inner else refers to if(k>100) because it is the closest if within the same block.
The if-else-if Ladder
A common programming construct that is based upon a sequence of nested ifs is the if-else-if ladder. It looks like this:
The if statements are executed from the top down. As soon as one of the conditions controlling the if is true, the statement associated with that if is executed, and the rest of the ladder is bypassed. If none of the conditions is true, then the final else statement will be executed. The final else acts as a default condition; that is, if all other conditional tests fail, then the last else statement is performed. If there is no final else and all other conditions are false, then no action will take place.
Here is a program that uses an if-else-if ladder to determine which season a particular month is in.
You might want to experiment with this program before moving on. As you will find, no matter what value you give month, one and only one assignment statement within the ladder will be executed.
Switch :
The switch statement is Java’s multiway branch statement. It provides an easy way to dispatch execution to different parts of your code based on the value of an expression. As such, it often provides a better alternative than a large series of if-else-if statements. Here is the general form of a switch statement:
{
case value1: // statement sequence
break;
case value2: // statement sequence
break;
.
.
. case valueN:
// statement sequence break;
default: // default statement sequence
}
The expression must be of type byte, short, int, or char; each of the values specified in the case statements must be of a type compatible with the expression. (An enumeration value can also be used to control a switch statement. Enumerations are described in Chapter 12.) Each case value must be a unique literal (that is, it must be a constant, not a variable). Duplicate case values are not allowed.
The switch statement works like this: The value of the expression is compared with each of the literal values in the case statements. If a match is found, the code sequence following that case statement is executed. If none of the constants matches the value of the expression, then the default statement is executed. However, the default statement is optional. If no case matches and no default is present, then no further action is taken.
The break statement is used inside the switch to terminate a statement sequence. When a break statement is encountered, execution branches to the first line of code that follows the entire switch statement. This has the effect of “jumping out” of the switch. Here is a simple example that uses a switch statement:
While the preceding example is, of course, contrived for the sake of illustration, omitting the break statement has many practical applications in real programs. To sample its more realistic usage, consider the following rewrite of the season example shown earlier. This version uses a switch to provide a more efficient implementation.
Thank You...!!!
Editing Friends You Can Download Our Materials For Free !!!
Join Telgram Channel :-
Only Eding Friends खालील व्हिडिओ पुर्ण बघा. 👇🏻
मित्रांनो आपल्याला Instagram वरती नक्की follow करा.
Thanks For Visit My Website.. 🙏
मित्रांनो आपल्याला Instagram वरती नक्की follow करा.
Thanks For Visit My Website.. 🙏