Control Statements in C++
Control Statement
C++ Program में ऐसे statements, जो अन्य statements या program execution के flow को control या handle करते हैं, इन्हे Control Statements कहा जाता है |
दूसरे शब्दों में हम कह सकते हैं कि जिन Statements पर program के कुछ अन्य statements निर्भर करते हैं, उन्हें Control Statements कहा जाता है |
जैसे -
- if . . . . . . else
- nested if
- ladder if
- switch . . . . . . case
- do . . . . . . .while
- while
- for
if . . . . else statement
यह एक Conditional Statement होता है | जब हम C++ program में कोई Condition apply करना चाहते हैं, तब if . . . . else statement का use करते हैं |
इन Statement का use करने के लिए if के बाद parenthesis () लगाया जाता है तथा parenthesis के अंदर condition लिखी जाती है : if (condition)
यदि parenthesis में लिखी हुई condition true होती है, तो if (condition) के बाद लिखे गए statement को execute किया जाता है तथा यदि condition false हो जाती है, तो program, if के बाद लिखे गए statement को jump कर जाता है तथा आगे else के code block में लिखे हुए statement को execute कर देता है |
Syntax:
if (Condition)
{
. . .. . . . . . . .
. . . . . . . . . . .
}
else
{
. . .. . . . . . . .
. . . . . . . . . . .
}
if parenthesis के अंदर condition apply करने के लिए Relational Operators की आवश्यकता होती है | C++ programming में 6 Relational Operators होते हैं -
> : Grater Than
< : Less Than
>= : Grater Or Equal
<= : Less Or Equal
== : Equal to
!= : Not Equal to
Example :
* Program to find greater number in two numbers:
Output:
टिप्पणियाँ
एक टिप्पणी भेजें