Wrox Programmer Forums
|
BOOK: Beginning JavaScript 2nd Edition For questions about Beginning Javascript 2nd Edition by Paul Wilton. (ISBN: 0-7645-5587-1). Published April 2004. For Javascript questions not specific to this book, please see the Javascript forum. If you have the 1st edition, please continue to use that forum instead at: http://p2p.wrox.com/forum.asp?FORUM_ID=21
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning JavaScript 2nd Edition 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 September 5th, 2004, 08:22 AM
Registered User
 
Join Date: Aug 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Help with for/in loop

I am so lost trying to make a program to display 1000 prime numbers using for/in loop with the numbers placed in an array. I would be happy if I could get for/in to display 0 - 1000 right now. Surely my instructor does not want me to type in the first 1000 prime numbers into an array.

var myArray = new Array(i = 0, i <= 1000, i++);
for (i in myArray)
 {
  document.write(myArray[i]);
 }
 
Old September 15th, 2004, 01:05 AM
Registered User
 
Join Date: Sep 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I don't know if this exactly meets the criteria, but...

var myArray = new Array();
for (i=0;i<=100;i++)
{
myArray[i]=i
}
for (i in myArray)
{
document.write(myArray[i]+"<br />");
}

However, I prefer using this:

var myArray = new Array();
for (i=0;i<=1000;i++)
{
myArray[i]=i
}
document.write(myArray);





Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with for-each loop athanatos XSLT 0 April 10th, 2006 07:20 PM
Do Until loop with IF crmpicco Classic ASP Databases 2 June 15th, 2005 05:35 PM
For....Loop kliu9 Excel VBA 5 February 10th, 2005 06:43 AM
Do Loop junemo Beginning PHP 8 July 28th, 2004 02:58 AM
nested while loop doesn't loop hosefo81 PHP Databases 5 November 12th, 2003 08:46 AM





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