If you want to execute all the statements related to the if statement if the condition is fulfilled and want to execute some other statements even if the condition is not fulfilled, then in such a situation if.....else statement is used.
If you want to execute all the related statements when the condition of the if statement is fulfilled and want to execute some other statements even if the condition is not fulfilled, then in such a situation if.....else statement is used.
if else Statement
if (condition)
{
_statement_block 1;
}
else
{
statement block 2;
}
Statement block 1 will be executed only if the condition given in the if statement is fulfilled and if the condition is unfulfilled, statement block 2 will be executed.
For example, if a condition has to be given at some place in a program that if the amount is less than 5000, then the payment is to be cashed, otherwise by check, then it will be written as follows using C programming language if else statement.
Read More:
यदि । स्टेटमेन्ट की शर्त पूर्ण होने पर उससे सम्बन्धित सभी स्टेटमेन्टस execute कराना चाहते हैं और शर्त के अपूर्ण होने पर भी कुछ अन्य स्टेटमेन्टस को execute करना चाहते हैं तो ऐसी परिस्थिति में if..... else स्टेटमेन्ट का प्रयोग किया जाता है।
if....... else स्टेटमेन्ट का प्रारूप
if else स्टेटमेन्ट
if (condition)
{
statement_block 1;
}
else
{
statement block 2;
}
स्टेटमेन्ट ब्लॉक 1 तभी execute होगा जब if स्टेटमेन्ट में दी गई शर्त पूर्ण होगी और शर्त के अपूर्ण रहने की परिस्थिति में स्टेटमेन्ट ब्लॉक 2 execute होगा, जैसे यदि किसी प्रोग्राम में किसी स्थान पर यह शर्त देनी है कि यदि amount 5000 से कम तो पेमेन्ट कैश करनी है अन्यथा चैक के द्वारा तो इसे सी प्रोग्रामिंग भाषा if else स्टेटमेन्ट का प्रयोग करके निम्नानुसार लिखा जाएगा।