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 Does anyone know how to use the incrementing number of a For Loop in a If statement

Before you post, read our: Rules & Posting Guidelines

Enjoy an ad free experience by logging in. Not a member yet? Register.
 07-19-2013, 01:58 PM PM User | #1 james909 New Coder   Join Date: Jul 2013 Posts: 18 Thanks: 0 Thanked 0 Times in 0 Posts Does anyone know how to use the incrementing number of a For Loop in a If statement How do I add the incrementing number of a for loop to an if statement inside the loop Here is the code: Code: for (var i=2; i<21; i++) { if (hulli == "Empty") { // do this } if (hulli == "Property") { // do this } } How do I include the value of i into the variable I am checking to make the statement check variables 'hull1', hull2', 'hull3' etc
 07-19-2013, 02:21 PM PM User | #2 Airblader Regular Coder   Join Date: Jan 2013 Location: Germany Posts: 578 Thanks: 4 Thanked 77 Times in 77 Posts Are you serious? http://www.codingforums.com/showthread.php?t=298614
 07-19-2013, 02:27 PM PM User | #3 Richter New Coder   Join Date: Jun 2012 Posts: 80 Thanks: 0 Thanked 18 Times in 18 Posts Why don't you change hull1, hull2, hull3 to array, it will work better then old one. Code: var Hull = [hull1, hull2, hull3]; //if you don't want to change all of your code so this is easy way to do it. // Need to minus 1 since array start from 0 but if your hull start from 0 then the minus 1 is no need. // You can use "var i = 1; i < 20;" insert what it wrote down here. for (var i = 2 - 1; i < 21 - 1; i++) { if (Hull[i]) == "Empty") {} if (Hull[i]) == "Property") {} }
 07-19-2013, 02:35 PM PM User | #4 Airblader Regular Coder   Join Date: Jan 2013 Location: Germany Posts: 578 Thanks: 4 Thanked 77 Times in 77 Posts @ Richter Please look into his other thread that I linked. He has both been given an answer to do "what he wants" and how to do it different. This is pretty much an exact copy of his question.
 07-19-2013, 03:02 PM PM User | #5 james909 New Coder   Join Date: Jul 2013 Posts: 18 Thanks: 0 Thanked 0 Times in 0 Posts An array won't work due to problems I explained on my other thread. I need to know how to add the value of i into the variable i'm checking in the if statements
 07-19-2013, 03:05 PM PM User | #6 Richter New Coder   Join Date: Jun 2012 Posts: 80 Thanks: 0 Thanked 18 Times in 18 Posts Thanks Airblader, when the time I wrote an answer, I didn't see you post until I post my answer (this webboard hasn't feature that alert a new post before user summit his post). @james909, Why do you have to split into new topic since it relate with your previous question ? Now you are the one that make me confuse. Last edited by Richter; 07-19-2013 at 03:08 PM..
 07-19-2013, 03:06 PM PM User | #7 Airblader Regular Coder   Join Date: Jan 2013 Location: Germany Posts: 578 Thanks: 4 Thanked 77 Times in 77 Posts And you got that answer in the other topic. It's still not very nice to say you will change it, but then just open a second thread with the same question. I'm out of here.
 07-19-2013, 03:26 PM PM User | #9 Airblader Regular Coder   Join Date: Jan 2013 Location: Germany Posts: 578 Thanks: 4 Thanked 77 Times in 77 Posts Code smell is a fact and I'm not going to go on trying to convince you that you can always use an array instead – whatever. It doesn't change the fact that your original question has been answered in the other thread. You just didn't read it carefully.
 07-19-2013, 03:31 PM PM User | #10 james909 New Coder   Join Date: Jul 2013 Posts: 18 Thanks: 0 Thanked 0 Times in 0 Posts I read the whole thread many times, your not understanding the question, I want to use For Loops with If statements inside The question is: Does anyone know how to use the incrementing number of a For Loop to check the value of a variable in an If statement that us inside said For loop? And the answer is..............
 07-19-2013, 03:36 PM PM User | #11 sunfighter Senior Coder   Join Date: Jan 2011 Location: Missouri Posts: 3,295 Thanks: 23 Thanked 473 Times in 472 Posts @james909, I don't know why you can't use an array. Life would be simpler. But to answer your question: you can concatenate two STRINGS, but that is not the same as hull1 being equal to "Empty". But we can get there. To concatenate : "hull".concat(i) Code that might help: Code: __________________ Evolution - The non-random survival of random variants.
 07-19-2013, 03:37 PM PM User | #12 Airblader Regular Coder   Join Date: Jan 2013 Location: Germany Posts: 578 Thanks: 4 Thanked 77 Times in 77 Posts The answer is in post #5 by Old Pedant (in the other thread)
 07-19-2013, 04:02 PM PM User | #13 james909 New Coder   Join Date: Jul 2013 Posts: 18 Thanks: 0 Thanked 0 Times in 0 Posts Yes Airblader troll, and you read my reply below(#6) that works for creating h1, h2, etc.., although it doesn't work in the way I need it to by creating h1w1, h1a1, etc.. for this i need to know how to: USE THE INCREMENTING NUMBER OF A FOR LOOP TO CHECK THE VALUE OF A VARIABLE IN AN IF STATEMENT INSIDE SAID FOR LOOP all i am getting is use this method instead, its better because.... when it actually isn't because you don't know my whole code, and why I specifically need to use the a for loop with if statements to create the variables
07-19-2013, 04:12 PM   PM User | #14
Regular Coder

Join Date: Jan 2013
Location: Germany
Posts: 578
Thanks: 4
Thanked 77 Times in 77 Posts
Quote:
 Originally Posted by james909 when it actually isn't because you don't know my whole code, and why I specifically need to use the a for loop with if statements to create the variables
Which just suggests flawed design, nothing else. You certainly aren't working on something that breaks code architecture techniques that have been used for years in multi million LoC projects.
Of course, a rewrite hurts. But the more you push it away, the more it will hurt. It starts with problems like these (and you should be happy Javascript offers you a solution – many languages wouldn't) and ends in total chaos.

Anyway – since you don't care about any of this, I'll try to be even more specific (though I thought pointing out the post should suffice):

Code:
window["hull" + i]

 07-19-2013, 04:36 PM PM User | #15 james909 New Coder   Join Date: Jul 2013 Posts: 18 Thanks: 0 Thanked 0 Times in 0 Posts THANK YOU AIRBLADER the: Code: window["hull" + i] code works perfectly as I need it, now I am happy to make my smelly code just how I need it

 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 06:12 PM.