Wrox Programmer Forums
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old November 21st, 2003, 01:35 AM
Registered User
Join Date: Nov 2003
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default loops

Why doesn't this count matches?

    for(counter4 = 0; counter4 > 5; counter4++)
    If(guessCode[4] == secretCode[counter4])
        rightColorScore = rightColorScore + 1;

If I understand, this should run guessCode[4] against secretCode[0-4}
if it see's any matches it should add 1 to the current value of
rightColorScore. HELP /thanks

Old November 21st, 2003, 04:59 AM
Friend of Wrox
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post

At the mo you have
for(counter4 = 0; counter4 > 5; counter4++) but I think you need
for(counter4 = 0; counter4 < 5; counter4++)
otherwise the loop will run zero times, because you are effectively saying:
1. assign the value 0 to counter4
2. do the following code while counter4 > 5 , which instantly fails because counter4 is < 5, so the following code doesn't get run at all.


Similar Threads
Thread Thread Starter Forum Replies Last Post
break for-each loops, or limit amount of loops warhero XSLT 2 July 4th, 2007 02:18 AM
Loops deontae45 VB.NET 2002/2003 Basics 2 September 28th, 2006 03:48 PM
Two Loops iloveoatmeal Classic ASP Basics 5 September 26th, 2005 09:59 AM
While loops and For loops in XSLT spencer.clark XSLT 1 August 5th, 2005 09:50 AM
loops Hudson40 Access VBA 1 February 4th, 2005 12:58 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.