![]() |
Available news archives:
comp.lang.tcl
-
comp.lang.python
-
comp.security.firewalls
-
sci.crypt -
comp.lang.php -
comp.lang.javascript
|
|
comp.lang.php archiveRe: $i++ problem understanding
From: JDS <jeffrey@example.invalid>
Date: Wed Oct 05 2005 - 15:44:16 CEST
On Wed, 05 Oct 2005 11:26:52 +0200, Pugi! wrote:
> Can anyone help me understand this or see the logic in it ?
I know others are explaining it already, but here is my go.
++ increments an integer variable by one.
Whenever ++ is tacked onto a variable, the variable is incremented by one.
++ can come *before* or *after* the variable, like this:
$i++
or this:
++$i
If ++ comes *before* the variable, then the statement on that line FIRST
If ++ comes *after* the variable, then the statement on that line first
For example:
{
// $c will be set to 3 and $b will be incremented to 3
This is different from this example:
{
// $b is incremented to 3 and then $c is set to 4
To use ++ unambiguously, always put it on a line by itself:
{
does the same thing as
{
That example is much less ambiguous than either of the first two.
later...
--
JDS | jeffrey@example.invalid
| http://www.newtnotes.com
DJMBS | http://newtnotes.com/doctor-jeff-master-brainsurgeon/
Received on Tue Oct 18 02:32:13 2005
|