Flash Website Builder- Trendy Site Builder is a Flash Site Building tool that helps users build stunning websites. Check Out Custom Custom Logo Design by LogoBee. Website Design and Free Logo Templates available.
 CodingForums.com Can I increment in a for in loop?

Before you post, read our: Rules & Posting Guidelines

Enjoy an ad free experience by logging in. Not a member yet? Register.
 03-02-2012, 07:28 AM PM User | #1 weismana81 New to the CF scene   Join Date: Mar 2012 Posts: 2 Thanks: 0 Thanked 0 Times in 0 Posts Can I increment in a for in loop? I'm super stuck. Is it possible to increment in a for...in loop? This is what I'm trying to do, but the increments aren't happening. Any help or advice is much appreciated!! Code: ```var i_1 = 3; var i_2 = 8; for (var key in data.id) { if ([key] < '4') { attach_to = '.active'; } else if ([key] > i_1 && [key] < i_2) { attach_to = '.item_' + i_1; } document.write(attach_to + '
' + i_1+ '
'); i_1 + 4; i_2 + 4; }```
 03-02-2012, 07:47 AM PM User | #2 Old Pedant Supreme Master coder!     Join Date: Feb 2009 Posts: 24,949 Thanks: 75 Thanked 4,307 Times in 4,274 Posts Increment what? You mean here: Code: ``` i_1 + 4; i_2 + 4;``` There is no incrementing being done by those statements. You add 4 to i_1 and then throw it on the floor. And do the same with i_2. Perhaps you meant to do Code: ``` i_1 += 4; i_2 += 4;``` THOSE statements will indeed increment each of those variables by 4. But this code makes no sense either: Code: ` if ([key] < '4')` (1) The syntax is illegal. You are using square brackets in an inaprorpriate place. (2) You are comparing something (not sure what, because the square brackets are illegal) to a *STRING* '4'. Are you aware that the string '1000000' is *LESS THANT the string '4'? If you want to compare NUMERIC values, use numbers, not strings. Finally, I don't know when or where this code fragment is supposed to run, but if it runs at any point in time *AFTER* the HTML page is finished loading, it will WIPE OUT ALL CONTENTS in the page, including even the code you show here. You can't use document.write after a page is loaded. __________________ An optimist sees the glass as half full. A pessimist sees the glass as half empty. A realist drinks it no matter how much there is.
 03-02-2012, 08:13 AM PM User | #3 weismana81 New to the CF scene   Join Date: Mar 2012 Posts: 2 Thanks: 0 Thanked 0 Times in 0 Posts Thanks so much for the guidance! I didn't mean to be vague with the code. This is part of a much bigger project and I was just trying to break it down the specific problem I was having. I was just using document.write to help me visualize the output. Silly mistake with the using strings instead of numbers :/ I've been using a lot of numbers with css to control behaviors on the page and I just... yeah... Anyway, I really appreciate your help!! += was definitely what I was looking for and you no doubt saved me a silly amount of time catching that 'number' thing. Thanks!

 Bookmarks

 Thread Tools Rate This Thread Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home :: Client side development     JavaScript programming         DOM and JSON scripting         Ajax and Design         JavaScript frameworks         Post a JavaScript     HTML & CSS     XML     Flash & ActionScript         Adobe Flex     Graphics and Multimedia discussions     General web building         Site reviews         Building for mobile devices :: Server side development     Apache configuration     Perl/ CGI     PHP         Post a PHP snippet     MySQL         Other Databases     Ruby & Ruby On Rails     ASP     ASP.NET     Java and JSP     Other server side languages/ issues         ColdFusion         Python :: Computing & Sciences     Computer Programming     Computer/PC discussions     Geek News and Humour Web Projects and Services Marketplace     Web Projects         Small projects (quick fixes and changes)         Medium projects (new script, new features, etc)         Large Projects (new web application, complex features etc)         Unknown sized projects (request quote)         Vacant job positions         Looking for work/ for hire         Project collaboration/ partnership         Paid work offers and requests (Now CLOSED)     Career, job, and business ideas or advice     Domains, Sites, and Designs for sale         Domains for sale         Websites for sale         Design templates and graphics for sale :: Other forums     Member Offers     Forum feedback and announcements

All times are GMT +1. The time now is 01:12 PM.