Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

syntax of for...loop with counter increase by 1/2 1

Status
Not open for further replies.

charlotte49er

Programmer
Nov 17, 2001
25
US
I am trying to populate a select box with values beginning with the var minHt and increasing by 0.5 until I reach maxHt. So the select box would list 25, 25.5, 26, etc. Here is the code snippet I have tried below but when I attempt to run it the browsers hang. Any suggestions are greatly appreciated.

Code:
for (i = minHt; i <= maxHt; i+0.5) {
  elevContent += '<option>' + i; 
}
 
Duh, as soon as I posted the question I came up with a solution. However, it would seem that you could accomplish the same thing by updating i in the &quot;for&quot; line.

Code:
for (i = minHt; i <= maxHt; i) {
  elevContent += '<option>' + i; 
  i = i+.5;
}
 
Or....


for (i = minHt; i <= maxHt; i+=.5) {
elevContent += '<option>' + i;
}

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

zen.gif
 
Or....


for (i = minHt; i <= maxHt; i+=((((100/10) * .5)/5)+(1 -.5))) {
elevContent += '<option>' + i;
}

it's friday........

-kaht

banghead.gif
 
correction

for (i = minHt; i <= maxHt; i+=((((100/10) * .5)/5)+(1 -1.5))) {
elevContent += '<option>' + i;
}

it's definitely friday when I'm debugging silly code....

-kaht

banghead.gif
 
Thx mwolf00. I knew I was missing something that was pretty simple. And kaht, you're killing me ! :) That's just what I needed to head into the weekend.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top