15. continue and break

Continue: In the following example loop prints the value but for which condition becomes true it just skip the code and next value is printed.

break: The PHP break keyword is used to terminate the execution of a loop prematurely.

while ($foo) {
continue;            // return back loop
break ;                // stop line
}

Example: 1

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


Example: 2

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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s