Use continue statement to get ten random numbers,each greater than the next in PHP

Description

The following code shows how to use continue statement to get ten random numbers,each greater than the next.

Example


<?php/*  w  ww . j  a va  2 s. c o m*/
  //init variables
  $count = 0;
  $max = 0;

  //get ten random numbers
  while($count < 10)
  {
    $value = rand(1,100);

    //try again if $value is too small
    if($value < $max)
    {
      continue;
    }

    $count++;
    $max = $value;
    print("$value <br>\n");
  }
?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    Language Basic »




PHP Introduction
PHP Operators
PHP Statements
Variable
PHP Function Create
Exception
PHP Class Definition