Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

for loop to print even numbers in lines

for loop loop

  • Please log in to reply
2 replies to this topic

#1 Guna Raj Kuikel

Guna Raj Kuikel

    CC Lurker

  • Just Joined
  • Pip
  • 1 posts

Posted 26 September 2011 - 05:32 AM

how can i write a javascript to print evens numbers from 0 to 50 in different lines as follows
2 4 6 8 10
12 14 16 18
20 22 24 26
28 30 32 34
36 38 40 42
44 46 48 50
  • 0

#2 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others

Posted 26 September 2011 - 05:57 AM

There are several ways to do it, but it will depend on the HTML on your page, among many things. What do you have so far?
  • 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/


#3 Vaielab

Vaielab

    Programming God

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1382 posts
  • Location:Quebec City
  • Programming Language:Java, C++, C#, PHP, JavaScript, Visual Basic .NET, Transact-SQL, ActionScript

Posted 26 September 2011 - 06:08 AM

One thing for sure, it will be easier if you have the same amount of number on each line.
Your first line have 5 number, and the other line have only 4

You will need a for that will look like this
for (i=0;i<=50;i+=2)

And maybe a other variable that you increment each time you enter the for, and you test for a modulus 4 like so
var % 4 == 0
And when it's true, you print a new line.
  • 0





Also tagged with one or more of these keywords: for loop, loop

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download