November 6th, 2012, 07:31 PM
12 year noob is very confused
hi my parents said if I can learn computer langages before summer i can go to computer camp which i would love to do but I am having trouble understanding couple of things. i am teaching myself and going through tutorials and sites but something are easy to understand and some are just confusing.
i learned a while loop and i understand the loop but it said i could nest a if statement in there which I did but it also said i could use a continue statment thats where i got confused. i got the break statment and how to use it, but the continue statment (i dont know if that is even a statment) does it just continue with the loop?
Can someone please just give me a simple explanation
November 6th, 2012, 07:33 PM
WRONG INFO GIVEN. ABORTING ^^
Last edited by notflip; November 7th, 2012 at 02:39 AM.
November 6th, 2012, 08:33 PM
Break ends the loop, continue finishes that iteration of the loop (it sends you back to the top of the code in the loop).
November 7th, 2012, 12:43 AM
Rukbat is right, notflip is wrong. The example notflip gave was the PHP.net example of what NOT to do with the "continue" command, and illustrates an unexpected behavior if you forget to put a semicolon at the end of the line. Notflip's example is also invalid PHP code since he used echo instead of print, which is a very important distinction in this example and basically nowhere else.
continue; is a statement which forces the loop to move on to the next item in the loop. In notflip's example, if it were syntactically correct and there was a semicolon after the continue, would print 0, 1, 3, 4. That's because the loop reaches the "continue" point at element 2 and never finishes execution.
Last edited by ManiacDan; November 7th, 2012 at 12:46 AM.
HEY! YOU! Read the New User Guide and Forum Rules
"They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin
"The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002
Think we're being rude? Maybe you asked a bad question
or you're a Help Vampire.
Trying to argue intelligently? Please read this.
November 7th, 2012, 11:08 AM
This is correct. You can use IF inside a LOOP and then use the continue statement to continue with the iteration without doing anything in that specific iteration, or just break to stop iterating the values that are left. Hope you can go to the camp.
Originally Posted by ManiacDan