Ask: Why can't print in for ($ I = 1; $ I <= 10; print $ I ++) be replaced with echo?

Source: Internet
Author: User
Ask: Why can't print in for ($ i1; $ I & lt; 10; print $ I ++) be replaced with echo? Ask: Why can't print in for ($ I = 1; $ I <= 10; print $ I ++) be replaced with echo?


Reply to discussion (solution)

For ($ I = 1; $ I <= 10; echo $ I ++ );
Parse error: syntax error, unexpected 'echo '(T_ECHO), expecting') 'in .....
That's the rule. why?

What exactly are the requirements to be printed on?

Strange way of writing

For ($ I = 1; $ I <= 10; echo $ I ++ );
Parse error: syntax error, unexpected 'echo '(T_ECHO), expecting') 'in .....
That's the rule. why?


I started to think about whether the returned values of print and echo are the same, but I couldn't understand it. I want to understand it. please give me some advice!

What exactly are the requirements to be printed on?


This problem was discovered by reading the manual ......

Strange way of writing


It's really strange. it's not written in this way at ordinary times.

For ($ I = 1; $ I <= 10; echo $ I ++ );
Parse error: syntax error, unexpected 'echo '(T_ECHO), expecting') 'in .....
That's the rule. why?


I started to think about whether the returned values of print and echo are the same, but I couldn't understand it. I want to understand it. please give me some advice!


Yes, it is the problem of return values. echo does not return values, so it is not allowed to be written in this way.

The syntax is incorrect.

for($i=1;$i<=10;$i++){    echo $i;}

The syntax is incorrect.

for($i=1;$i<=10;$i++){    echo $i;}


I know I can write it like this. I want to understand why an error occurs when I replace print with echo when I write a line.

For ($ I = 1; $ I <= 10; echo $ I, $ I ++ );

The above statement is really strange.

The syntax is incorrect.

for($i=1;$i<=10;$i++){    echo $i;}


I know I can write it like this. I want to understand why an error occurs when I replace print with echo when I write a line.



The moderator has answered you, because print always returns 1, while echo does not return the value. Therefore, the original statement is equivalent to for ($ I = 1; $ I <= 10; 1) {$ I ++;} and for ($ I = 1; $ I <= 10;) {$ I ++;}, apparently echo will have an error

Agree with the 7th floor + 1

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.