You can get the same output with for and while loops:
While:
$i = 0;
while ($i <= 10){
print $i."\n";
$i++;
};
For:
for ($i = 0; $i <= 10; $i++){
print $i."\n";
}
But which one is faster?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
That clearly depends on the particular implementation of the interpreter/compiler of the specific language.
That said, theoretically, any sane implementation is likely to be able to implement one in terms of the other if it was faster so the difference should be negligible at most.
Of course, I assumed
whileandforbehave as they do in C and similar languages. You could create a language with completely different semantics forwhileandfor