Page 1 of 1

continue statement

Posted: Tue Jul 01, 2003 1:31 pm
by kendall
Hello,

Im trying to understand the correct usage of the continue statement...im having a bit of a hard time comprehending the manual's examples

i have the following code

[syntax=php]for($i=0; $i<5 ; $i++){
if($imagetype != 'jpeg')
continue;

if($imagesize>max_size)
continue

savefile($image);
}[/syntax]

Now what i am attempting is that if the imagetype is not jpeg or if the imagesize is over the max skip this file and go to the next file to validate other wise it will savefile($image);
however i dont seem to be getting the desired result

can someone explain what im suppose to do with the continue?

Kendall

Posted: Tue Jul 01, 2003 1:36 pm
by Stoker
continue; will skip the rest of the current loop iteration and go to next..
break; will end the whole loop statement.

Posted: Tue Jul 01, 2003 1:37 pm
by m@ndio
The continue statement does the following:

breaks out of the current loop and "continues" with the next bit

continue statement

Posted: Tue Jul 01, 2003 1:48 pm
by kendall
Elobrating on what m@ndio said,

what your saying is that if

if($imagetype == 'jpeg'){
it will continue on to the if 2 statement?
}

if($imagesize > size) // this is the if 2 statement?

or is it the save statement?

savefile($image); ?

Posted: Tue Jul 01, 2003 2:07 pm
by Stoker

Code: Select all

<?php

  define ('COLD',35);
  define ('FROZEN',25);

  for ($i=40 ; $i ; $i--)
  {
    # Do some "cool stuff"
    echo 'Current temp is '. $i;
    if ($beer < COLD) continue;  // This will return to the top of the loop and keep it cooling (Until $i is less than 35)
    echo 'Its cold now '.$i;
    if ($beer < FROZEN) break;  //  This will exit the forloop and continue with "its frozen" when $i reaches 25

  }
  echo 'Ugh, it frozen!';
?>