continue statement

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

continue statement

Post 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
User avatar
Stoker
Forum Regular
Posts: 782
Joined: Thu Jan 23, 2003 9:45 pm
Location: SWNY
Contact:

Post by Stoker »

continue; will skip the rest of the current loop iteration and go to next..
break; will end the whole loop statement.
User avatar
m@ndio
Forum Regular
Posts: 163
Joined: Fri Jun 06, 2003 12:09 pm
Location: UK

Post by m@ndio »

The continue statement does the following:

breaks out of the current loop and "continues" with the next bit
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

continue statement

Post 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); ?
User avatar
Stoker
Forum Regular
Posts: 782
Joined: Thu Jan 23, 2003 9:45 pm
Location: SWNY
Contact:

Post 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!';
?>
Post Reply