2014. szeptember 11., csütörtök

break: kiugrás a ciklusból

pl:
<!DOCTYPE html PUBLIC
    "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Listing 5.10 Using the break Statement</title>
</head>
<body>
<div>
<?php
$counter = -4;
for ( ; $counter <= 10; $counter++ ) {
    if ( $counter == 0 ) {
        break;
    }
    $temp = 4000/$counter;
    print "4000 divided by $counter is... $temp<br />";
}
?>
</div>
</body>
</html>
Eredmény:

4000 divided by -4 is... -1000
4000 divided by -3 is... -1333.3333333333
4000 divided by -2 is... -2000
4000 divided by -1 is... -4000

Nincsenek megjegyzések:

Megjegyzés küldése