C#
using System;
class onetoten
{
public static void Main ()
{
for (int x = 0; x < 11; x++)
{
Console.Write(x);
}
}
}
tayspen
<Insert title here>
1,622 posts since Jul 2005
Reputation Points: 84
Solved Threads: 99
3.) VB Script
MsgBox "1, 2, 3, 4, 5, 6, 7, 8, 9, 10", vbOKOnly, "Count!"
:)
tayspen
<Insert title here>
1,622 posts since Jul 2005
Reputation Points: 84
Solved Threads: 99
C#
using System;
class onetoten
{
public static void Main ()
{
for (int x = 0; x < 11; x++)
{
Console.Write(x);
}
}
}
Blah... you have to show off the features of object orientation:
using System;
using System.Collections.Generic;
using System.Text;
namespace counting
{
public class Counter
{
private int count = 1;
public int Count
{
get
{
return count;
}
set
{
count = value;
}
}
}
class Program
{
public static void Main()
{
Counter number = new Counter();
do
{
Console.WriteLine(number.Count.ToString());
number.Count++;
} while (number.Count <= 10);
}
}
}
Looks like a lot more code... Well, it is, but now I've created a reusable object that does all of the work, and I could change it later on so to have a different starting number, or even determine the number some other way. :cool:
alc6379
Cookie... That's it
2,820 posts since Dec 2003
Reputation Points: 186
Solved Threads: 147
That is indeed a better way you did it though. But alot more code :)
Another one; Doesnt really 'count" but it prints .
C#
MessageBox.Show("1, 2, 3, 4, 5, 6, 7, 8, 9, 10");
Yea, it's beginner, yet it gets the job done. Now off to create a complicated one.
Jess, was this thread inspire by the one on PFO ;).
tayspen
<Insert title here>
1,622 posts since Jul 2005
Reputation Points: 84
Solved Threads: 99
Perl:
print "$_\n" for 1..10
Rashakil Fol
Super Senior Demiposter
2,658 posts since Jun 2005
Reputation Points: 1,135
Solved Threads: 176
FASM Assembly:
format PE console
entry start
include 'C:\fasmw\include\win32a.inc'
;======================================
section '.data' data readable writeable
;======================================
num_fmt db '%d',10,0
;=======================================
section '.code' code readable executable
;=======================================
start:
mov ebx,10
.again:
lea eax,[ebx-11]
neg eax
ccall [printf],num_fmt,eax
dec ebx
jnz .again
stdcall [ExitProcess],0
;=====================================
section '.import' import data readable
;=====================================
library kernel,'kernel32.dll',\
msvcrt,'msvcrt.dll'
import kernel,\
ExitProcess,'ExitProcess'
import msvcrt,\
printf,'printf'
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
Haskell:
main = mapM (putStr . (++ "\n") . show) [1..10]
Rashakil Fol
Super Senior Demiposter
2,658 posts since Jun 2005
Reputation Points: 1,135
Solved Threads: 176
Well, since the goal is to PRINT 1 - 10, I give you:
PostScript
%!PS
% position constants and procs
/x 72 def
/yPos 700 def
/y {yPos lnHeight sub dup /yPos exch def} bind def
% font constants
/fontName /Courier def
/ptSize 12 def
/lnHeight ptSize 1.2 mul def
% set the font
fontName ptSize selectfont
% for loop to paint numbers
1 1 10 { 5 string cvs x y moveto show} for
% commit page image to currentpage
showpage
tgreer
Made Her Cry
2,118 posts since Dec 2004
Reputation Points: 227
Solved Threads: 37
I would've done one in Tama, but it's not Turing complete so doesn't deserve it.
Ruby:
(1..10).each { |x| puts x }
Rashakil Fol
Super Senior Demiposter
2,658 posts since Jun 2005
Reputation Points: 1,135
Solved Threads: 176
My Tama, or some other language I haven't heard of? If you're talking about mine, yea, it's pretty lame. :) I never got around to really improving it.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
Here's um, another Scheme version:
(let loop ((i 1))
(cond ((<= i 10)
(display i)
(loop (+ i 1))))
And another...
(define (range n m)
(if (> n m)
'()
(cons n (range (+ n 1) m))))
(for-each display (range 1 10))
Rashakil Fol
Super Senior Demiposter
2,658 posts since Jun 2005
Reputation Points: 1,135
Solved Threads: 176
Ohhh yeahh. Predicates with internal state.
#include <iostream>
#include <list>
#include <algorithm>
using namespace std;
template <class T>
inline void PRINT_ELEMENTS(const T& coll, const char* optc="")
{
std::cout << optc;
typename T::const_iterator pos;
for (pos=coll.begin(); pos != coll.end(); ++pos)
{
std::cout << *pos << " ";
}
}
class IntSequence
{
public:
//constructor
IntSequence(int initialValue)
: value(initialValue) { }
//function call
int operator() ()
{
return value++;
}
private:
int value;
};
int main()
{
list<int> coll;
//insert values from 1 to 9
generate_n(back_inserter(coll), //start
10, //number of elements
IntSequence(1)); //generates values
PRINT_ELEMENTS(coll);
cout << endl;
}
server_crash
Postaholic
2,111 posts since Jun 2004
Reputation Points: 113
Solved Threads: 20
Java
class Pedantic
{
public static void main(String[] args)
{
for(int i=1; i <=10; i++)
{
System.out.println(i);
}
}
}
iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439