### Thread: Update form in dreamweaver cc

Page 3 of 3 First 123
Now I get it!

so in other words, what would work would be to write it like this: (==5) right? Amazing! I'm finally learning something. thank you
Yes, it would work. The script would run without an error, but the loop would not execute.

== is a comparison operator

= is an assignment operator
2. No Profile Picture
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
Nov 2013
Posts
33
Rep Power
2
Originally Posted by Nilpo
Yes, it would work. The script would run without an error, but the loop would not execute.

== is a comparison operator

= is an assignment operator
Let me try to explain this to myself:

So it wouldn't work because \$count has been set to 1 and in order to get to 5 it must go through a loop that will bring it to 5 by adding ++\$count at each loop but since my expression does not include a "<", then the loop as nowhere to start or to get to 5 since it can get initialized by increment of 1. Is my logic flawed?
3. This is correct. Simply put: \$count is initialized with 1. The loop starts every iteration by checking if \$count equals 5. Since it doesn't, the loop immediately stops. That's it.

Two things, though:

Loops that are based on counters should be written as for loops. It looks like this:

PHP Code:
``` for (\$counter = 1; \$counter <= 10; \$counter++) {     echo \$counter; }  ```
As you can see, all the data for the counter is on top: You first initialize the counter variable. In this case, \$counter starts at 1. Then you specify the loop condition. In this case, \$counter must not exceed 10. And then you define what should happen to the counter variable. In this case, it's simply incremented.

When working with counters, for loops are preferable over general while loops, because they're more compact, easier to read and clearer.

Secondly, you should avoid the term "doesn't work". Programming is about being precise. Saying that something "doesn't work" isn't precise at all. It could mean pretty much anything: that the program has crashed, or that the program doesn't do what it should, or that something unexpected has happened, or whatever.

I'm pointing this out because people in this forum often tell us that their code "doesn't work", and then we have a hard time trying to find out what they actually mean. It's better to use precise language.