আগামী ১৫ ডিসেম্বর -২০১৭ তারিখ থেকে শুরু হচ্ছে পাঁচ মাস ব্যাপী Professional Web Design and Development with HTML, CSS PHP,MySQL,JavaScript, AJAX, JQUERY, Bootstrap and Live Project কোর্সের ৮৭ তম ব্যাচ এবং ২৬ ডিসেম্বর-২০১৭ তারিখ থেকে শুরু হচ্ছে চার মাস ব্যাপী Zend PHP-7 Certified PHP Engineering (Advance PHP) কোর্সের ৩৫ তম ব্যাচ। প্রত্যেকটি কোর্স এর ফী নির্ধারণ করা হয়েছে ৩০,০০০/= আগ্রহীদেরকে অতিসত্বর মাসুদ আলম স্যার এর সাথে যোগাযোগ করতে অনুরোধ করা যাচ্ছে। স্যার এর মোবাইল: 01722 81 75 91

PHP Control Structure Part-4: break, continue, goto

What is a break statement in PHP?

In PHP or any programming language, if any specific condition is true, then the break statement is used to stop the program execution immediately and exit the program. The loop or switch statement use break statement in PHP.

What is the flow chart of break statement in PHP?

PHP Break statement flowchart

What is the syntax of break statement in PHP?

break;

How does the break statement work in PHP?

The break statement usually used in loop or switch statement in PHP.

Working Break

Examples of break statements in PHP:

When the value of $ i is 6, the program will immediately stop its execution. So the result here will be 1-5

<?php
for($i=1;$i<=10;$i++){
if($i==6){
break;
}
echo $i,"<br>";
}

Here in the example below, the date function will check which day number in week, and when a match with a case, the break statement will immediately stop the execution of the program.

<?php
$day= date('w');
//echo $day;
switch ($day) {
   case 1:
           echo "Today is Monday";
           break;
   case 2:
            echo "Today is Tuesday";
           break;
   case 3:
            echo "Today is Wednesday";
           break;
   case 4:
             echo "Today is Thursday";
           break;
   case 5:
            echo "Today is Friday";
           break;
   case 6:
            echo "Today is Saturday";
           break;
   default:
            echo "Today is Sunday";
           break;
}
?>

What is the continue statement in PHP?

PHP or any programming language, if any specific condition is true, then continue statement skip the program execution and go to the next program.

What is the flow chart of the continue statement in PHP?

PHP continue statement flow chart

What is the syntax of the continue statement in PHP?

continue;

How does the continue statement work in PHP?

The continue statement in PHP is commonly used in loop. In other words, a certain condition is true in the loop, by continuing to skip the program execution and continuing to go to the next program works. See the image below.

PHP Continue Statement

Example of a continuation statement in PHP:

In the example below, when the value of $i is 6, the program will immediately skip its execution and go to the next program. So the results here will be 1 2 3 4 5 7 8 9 10

<?php
for($i=1;$i<=10;$i++){
if($i==6){
continue;
}
echo $i,"<br>";
}

What is goto statement on PHP?

PHP goto statement

In PHP or any programming language, if a specific condition is true, goto statement is used to immediately transfer or skip to the any other program.

What is the flow chart of goto statement in PHP?

PHP Goto Statement Flow Chart

What is the syntax of Goto statement in PHP?

goto label;
... .. ...
... .. ...
... .. ...
label: 
statement;
... .. ...

How does goto statement work in PHP?

When a certain condition is true, select a label with goto and immediately transfer to a program in another program. Notice the following image:

Working PHP goto

Example of goto statement in PHP:

Example 1:

<?php
goto a;
echo 'Foo';
  
a:
echo 'Bar';
?>

The above example will be output:

Bar

Example 2:

<?php
for($i=0,$j=50; $i<100; $i++) {
  while($j--) {
    if($j==17) goto end; 
  }  
}
echo "i = $i";
end:
echo 'j hit 17';
?>

The above example will be output:

j hit 17

Hi, My name is Masud Alam, love to work with Open Source Technologies, living in Dhaka, Bangladesh. I’m a Certified Engineer on ZEND PHP 5.3, I served my first five years a number of leadership positions at Winux Soft Ltd, SSL Wireless Ltd, Canadian International Development Agency (CIDA), World Vision, Care Bangladesh, Helen Keller, US AID and MAX Group where I worked on ERP software and web development., but now i’m a founder and CEO of TechBeeo Software Company Ltd. I’m also a Course Instructor of ZCPE PHP 7 Certification and professional web development course at w3programmers Training Institute – a leading Training Institute in the country.

Leave a Reply

Your email address will not be published. Required fields are marked *