SitePoint Sponsor |
|
User Tag List
Results 1 to 4 of 4
Thread: JavaScript Conditionals
-
Jun 21, 2002, 07:51 #1
JavaScript Conditionals
Okay, I've just finished a big thick book on JavaScript, but unfortunately something wasn't explained to me. I know lost of conditionals, like ==, &&, +=, <=, !=, >=, <, and >, but when I look at advanced scripts I see ++...can someone explain this one to me? I'd also appreciate some sort of list of conditionals, since there are probably others.
Greatly Appreciated!Parms18
-
Jun 21, 2002, 08:35 #2
- Join Date
- Feb 2002
- Location
- Gatwick, UK
- Posts
- 1,206
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
It's not a conditional test.
It's an arithmatic function called autoincrement ( and hencely autodeincrement )
$i=5;
$i++; // return $i then increment it
++$i; // increment $i then return it
thusly if you did:
$i = 20;
$d = $i++; // $i = 21 and $d = 20
$i = 20;
$d = ++$i; // $i = 21 and $d = 21
The same is true of --
if you want to remember which returns which think of it from left to right. $d=$i++; < thus $d = $i THEN you increment it. $d=++$i < thus $d = Increment THEN $i
okie
Hope this helps
Flawless---=| If you're going to buy a pet - get a Shetland Giraffe |=---
-
Jun 21, 2002, 08:38 #3
- Join Date
- Feb 2002
- Location
- Gatwick, UK
- Posts
- 1,206
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
After thought:
you might have seen this in a for loop
for ($i=0;$i<10;$i++)
ie:
for (starting value; condition to end upon; upon each iteration)
hencely on the first iteration $i = 0 - since it retruns THEN increments.
This is used less often now as people prefer to use
for (number .. end )
as a sequence system - but this is because they are normally
just caring about the number of times their iteration gets run - rather than the number of the current iteration.
Flawless
( btw - excuse the $i's - i'm working my *** of in perl modules right now )---=| If you're going to buy a pet - get a Shetland Giraffe |=---
-
Jun 22, 2002, 08:34 #4
- Join Date
- Jan 2002
- Location
- London
- Posts
- 3,509
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
As well as the ++ (increment) and -- (decrement) operators, there are also may operators for manipulating a variable's value relative to its present variable.
e.g. "tmp *= 2" is the same as "tmp = tmp * 2"
Any good reference on JS or C++ should list and explain all of these operators, such as Microsoft's JScript reference (see my sig).
M@rcoMarcusJT
- former ASP web developer / former SPF "ASP Guru"
- *very* old blog with some useful ASP code
- Please think, Google, and search these forums before posting!
Bookmarks