Jump to content

for loop to print even numbers in lines

- - - - -

  • Please log in to reply
2 replies to this topic

#1
Guna Raj Kuikel

Guna Raj Kuikel

    Newbie

  • Members
  • Pip
  • 1 posts
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

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 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
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?
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
Vaielab

Vaielab

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 547 posts
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.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users