Control Statements in PHP in Hindi – PHP में कंट्रोल स्टेटमेंट क्या है?

PHP में Control Statements वे statements होते हैं जिनका इस्तेमाल प्रोग्राम के flow को कंट्रोल करने के लिए किया जाता है। Control Statements को Control Structures भी कहा जाता है। 

Control Statements की मदद से हम Code के Execution को अलग-अलग Conditions के आधार पर Manage कर सकते हैं।

PHP में मुख्य रूप से तीन प्रकार के control statements होते हैं:

  1. Decision-Making Statements 
  2. Looping Statements 
  3. Jumping Statements 

1:- Decision-Making Statements in Hindi

PHP में, Decision making statements का इस्तेमाल एक या एक से अधिक conditions के आधार पर decision (निर्णय) लेने के लिए किया जाता है। इसके प्रकार निम्नलिखित हैं:-

(a) if Statement

if Statement का उपयोग तब किया जाता है जब हमें किसी Condition के True (सत्य) होने पर किसी कोड को Execute करना हो।

Syntax:

if (condition) {
    // Code to be executed if condition is true
}

(b) Multiple IF Statement

Multiple IF का इस्तेमाल तब किया जाता है जब एक से अधिक conditions को check करने की आवश्यकता होती है। हर condition अलग-अलग चेक होती है और हर condition का अपना output हो सकता है।

Syntax 

if (condition1) {
    // Code to be executed if condition1 is true
}

if (condition2) {
    // Code to be executed if condition2 is true
}

if (condition3) {
    // Code to be executed if condition3 is true
}

(c) if…else Statement

इसका उपयोग तब किया जाता है जब हमें कंडीशन के true होने पर एक code को और कंडीशन के False होने पर दूसरे कोड को Execute करना हो।

Syntax:

if (condition) {
    // Code to be executed if condition is true

} else {
    // Code to be executed if condition is false
}

(d) if…elseif…else Statement

इसका उपयोग बहुत सारीं Conditions को Check करने के लिए किया जाता है।

Syntax:

if (condition1) {
    // Code to be executed if condition1 is true

} elseif (condition2) {
    // Code to be executed if condition2 is true

} else {
    // Code to be executed if none of the conditions are true
}

(e) switch Statement

switch Statement का इस्तेमाल तब किया जाता है जब हमें एक Variable की Value के अनुसार अलग-अलग Code को Execute करने होते हैं।

Syntax:

switch (variable) {

    case value1:
    // Code to be executed if variable == value1
    break;

    case value2:
        // Code to be executed if variable == value2
        break;

    default:
        // Code to be executed if none of the cases are true
}

2:- Looping Statements in Hindi

Looping Statements का इस्तेमाल code को एक से ज्यादा बार execute करने के लिए किया जाता है। इसमें code को तब तक execute किया जाता है जब तक कि condition को प्राप्त नहीं कर लिया जाता.

Looping Statement के निम्नलिखित प्रकार के होते हैं:-

  1. while loop
  2. do-while loop
  3. for loop

(a) while Loop

while Loop तब तक Execute होते रहता है जब तक कि कंडीशन True रहती है।

Syntax

while(condition)
{
statement1;

statement2;

-------------
}

(b) do while Loop

do while Loop में कंडीशन सबसे Last में Check होती है, इसलिए यह Loop कम से कम एक बार जरूर Execute होता है।

Syntax:

do{

Statement1;
Statement2;

--------------
}While (condition);

(c) for Loop

For Loop एक ऐसा loop है जिसमें स्टेटमेंट के run होने से पहले condition की जांच की जाती है. यदि condition सत्य (true) होती है तो स्टेटमेंट run होती है, और यदि condition असत्य (false) है तो for loop को समाप्त (terminate) कर दिया जाता है

Syntax:

for(initial condition, test condition; increment or decrement)
{
statement1;
statement2;
}

(d) foreach Loop

foreach Loop का उपयोग Arrays और  objects के साथ काम करने के लिए किया जाता है। यह array के हर element को एक-एक करके access करता है, जिससे हम data को आसानी से process कर सकते हैं।

Syntax:

foreach ($array as $value) {

    // Code to be executed for each value

}

3:- Jumping Statements in Hindi

Jumping statements का उपयोग program के flow को एक point से दूसरे point पर ट्रांसफर करने के लिए किया जाता है।

(a) break Statement

इसका उपयोग किसी Loop या switch Statement से बाहर निकलने के लिए किया जाता है।

Syntax:-

break; 

(b) continue Statement

इसका उपयोग मौजूदा Iteration को Skip करके अगले Iteration में जाने के लिए किया जाता है।

Syntax:-

continue; 

(c) goto Statement

goto Statement का उपयोग Code के Execution को एक विशेष Label पर ट्रांसफर करने के लिए किया जाता है।

Syntax 

goto label;
// Some code here

label:
// Code to be executed

इसे पढ़ें:

निवेदन:-अगर आपका किसी subjects को लेकर कोई सवाल या कोई topics है तो हमें बतायें हम उसको एक या दो दिन के अंदर यहाँ हिंदी में Publish करेंगे।

Leave a Comment