Okay, here's the code: <?php $x=1; while($x<5); { echo "hello"; $x++; } ?> It's quite basic, but after ages of troubleshooting, it's just not working! Can anybody find what the problem is here? I'm a noob, so be kind. Thanks soo much!
It's the semicolon after your while line. So it's stuck right there and looping since it's never going through your loop. Code should be: <?php $x=1; while($x<5) { echo "hello"; $x++; } ?> PHP:
Thanks. I came across another problem though: <?php $x=1; $y="hello "; while($x<2) { echo $y; $x++; } if (strlen ($y)==2); echo "goodbye"; ?> The problem here is that it's still saying goodbye, even though hello has more than 2 characters.
If you only want goodbye to display if $y is 2 characters long then you need to put it in a clause <?php $x=1; $y="hello "; while($x<2) { echo $y; $x++; } if (strlen ($y)==2) { echo "goodbye"; } ?> PHP:
Thank you so much. I keep getting hung up on the sytax. Is there anything I could download where I can be shown what's wrong before I save it and test it? Thanks again for the help.
Well if you want a full blown IDE for PHP and other web/non-web languages I strongly recommend Netbeans. Out of every free heavy duty IDE I've tried it seems to be the best. It will tell you if something is wrong with your syntax (in your case, the extra semi-colons), help you auto-complete method/etc. names, has awesome documentation for the languages you'll be working with, and continuously adds support for popular frameworks of languages (jQuery for example). I'm not going to parrot all of its features, just goto http://www.netbeans.com/
Use dreamweaver CS5, go to code view options then onto highlight invalid code, it will show you an error if there is one and highlight in yellow. Glen
It's insignificant for a small amount of loops. It also changes the behavior in a for() loop. The real significant difference is that the former increases, and THEN returns the value, while the latter returns, and then increases.