# Thread: Can you count to ten?

1. ## Can you count to ten?

Little fun game. Write a program segment that prints the
numbers from 1 to 10, You can use any language you wish, and
any legal syntax of that chosen language to do so. Let's see how many
ways there are to do so in as many languages as possible.

I'll Start

Code:
```with Ada.Text_IO;

for I in 1 .. 10 loop
Put_Line (I);
end loop;```

2. Bash
Code:
`\$ for ((i=1;i<=10;i++)); do echo \$i ; done`
Awk
Code:
`\$ awk 'BEGIN { for ( i = 1 ; i <= 10 ; i++ ) { print i } }'`
Perl
Code:
`\$ perl -e 'print join("\n",(1..10)) . "\n";'`

3. C#:
Code:
```        var ten = "1,2,3,4,5,6,7,8,9,10".Replace(",", "\n");
Console.WriteLine(ten);```

4. Python:

Code:
```for i in range(1,11):
print i```

5. Fortran, of course

Code:
`print *, (/ (i, i = 1, 10) /)`

6. Originally Posted by gemera
Python:

Code:
```for i in range(1,11):
print i```
Or even more succinctly:

Code:
`print range(1, 11)`
There was no stated requirement that each number be on its own line.

7. C:
Code:
```int j = 0;
while (true) {
for (int i = 5; i < 35; i += 3) {
char* s = malloc(i);
sprintf(s, "%d", ((i - 5) / 3) + 1);
printf("%s\n", s);
j = (i / 2) * 6;
}
if (j > 10) break;
}```

8. @Elkvis If list notation is acceptable it would even be possible to go raw with:

Code:
`range(1,11)`
Now, that's snappy code.

9. LOL @ Yarin

Rust:
Code:
```for i in 0..11 {
print!("{} ", i);
}```

10. BASIC

FOR..NEXT loop

Code:

Code:
```FOR I = 1 TO 10PRINT INEXT I
END```
REPEAT..UNTIL loop

Code:
```I=0
REPEATPRINT I
I=I+1UNTIL I>=11
END```

11. Java:

Code:
```public class Program {
public static void main(string[] args) {
for (int i =  1; i <= 10; ++i)
System.out.print(" " + i);
}
}```
C - absolutely horrible way to do it:

Code:
```int a = 1, b = 2, c = 3, d = 4,  e = 5, f = 6, g = 7,  h = 8, i = 9, j = 10;
int *ptr1 = &a;
int *ptr2 = &b;
int *ptr3 = &c;
int *ptr4 = &d;
int *ptr5 = &e;
int *ptr6 = &f;
int *ptr7 = &g;
int *ptr8 = &h;
int *ptr9 = &i;
int *ptr10 = &j;

printf(" %d", *ptr1);
printf(" %d", *ptr2);
printf(" %d", *ptr3);
printf(" %d", *ptr4);
printf(" %d", *ptr5);
printf(" %d", *ptr6);
printf(" %d", *ptr7);
printf(" %d", *ptr8);
printf(" %d", *ptr9);
printf(" %d\n", *ptr10);```

12. Code:
```    char cs[] = "TWENTYFOUR";
char *ptr = cs;
while (*ptr++) {
printf("%d\n", (int) (ptr - cs));
}```

13. You know, I thought I'd be clever and try to do this in Haskell. Then I got frustrated and just quit lol XD

14. Originally Posted by MutantJohn
You know, I thought I'd be clever and try to do this in Haskell. Then I got frustrated and just quit lol XD
Code:
`main = print([1..10])`

15. Originally Posted by gemera
@elkvis if list notation is acceptable it would even be possible to go raw with:

Code:
`range(1,11)`
now, that's snappy code.
matlab:

Code:
`1:10`