1
   

For loop to find even numbers

 
 
Reply Mon 26 Sep, 2011 07:23 am
how can i write a script 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
  • Topic Stats
  • Top Replies
  • Link to this Topic
Type: Question • Score: 1 • Views: 1,719 • Replies: 6
No top replies

 
DrewDad
 
  1  
Reply Mon 26 Sep, 2011 08:07 am
@gunarajk,
What scripting language are you using?
Ragman
 
  1  
Reply Mon 26 Sep, 2011 11:09 am
@DrewDad,
javascript..so it says in his forum categories
0 Replies
 
gunarajk
 
  1  
Reply Wed 28 Sep, 2011 10:05 am
@DrewDad,
How to display the following using a for loop in JavaScript?
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
DrewDad
 
  1  
Reply Wed 28 Sep, 2011 11:21 am
@gunarajk,
I don't know javascript exactly, but this should get you started:

Const CRLF= (characters for carriage return and line feed)
Dim strOutput
strOutput = ""
for x = 1 to 50
if x modulo 2 = 0 then strOutput = strOutput & x
if x modulo 2 = 0 and x modulo 10 <> 0 then strOutput = strOutput & " "
if x modulo 10 = 0 then strOutput = strOutput & CRLF
next x
echo strOutput
DrewDad
 
  1  
Reply Wed 28 Sep, 2011 11:24 am
@DrewDad,
There are various ways to make this more efficient, but it's hardly necessary for such a simple script.
gunarajk
 
  1  
Reply Thu 29 Sep, 2011 08:17 am
@DrewDad,
IF there are many why dont you share one with me. As i m the begineer in such things. So give me one script which you mentioned as simple
0 Replies
 
 

Related Topics

 
  1. Forums
  2. » For loop to find even numbers
Copyright © 2024 MadLab, LLC :: Terms of Service :: Privacy Policy :: Page generated in 0.04 seconds on 05/18/2024 at 12:28:22