
Originally Posted by
mr.vain
What do you think?
It depends on the context. When you see the continue keyword you immediately see that the condition is crucial for execution of the rest of the iteration, whereas if you enclose the code in brackets you don’t know if any other code is executed even though the condition has not been met, until you scroll down to the bottom.
PHP Code:
foreach($files as $file) {
if($file != "index.html") { // if file is not index.html then delete it
unlink('uploads/cache/' . $file);
}
// something else can happen here
}
foreach($files as $file) {
if ($file == "index.html") { // if file is index.html then go to next one
continue;
}
// nothing else will happen here
unlink('uploads/cache/' . $file);
}
Notice how it changes how the code reads.
Always aim for writing code that is easiest to read and makes sense at first glance.
Bookmarks