Below you will find a sample program for every language available on Ideone. Click fork to execute the code.
- go to:
- Ada95
- Assembler 32bit
- Assembler 32bit
- AWK
- AWK
- Bash
- BC
- Branf**k
- C
- C#
- C++
- C++ 4.3.2
- C++14
- C99
- Clips
- Clojure
- Cobol
- COBOL 85
- Common Lisp
- Common Lisp
- D
- D
- Erlang
- F#
- Fantom
- Forth
- Fortran
- Go
- Groovy
- Haskell
- Icon
- Intercal
- Java
- Java7
- JavaScript
- JavaScript
- Lua
- Nemerle
- Nice
- Nim
- Node.js
- Objective-C
- Objective-C
- Ocaml
- Octave
- Oz
- Pascal
- Pascal
- Perl
- Perl
- PHP
- Pike
- Prolog
- Python
- Python 3
- R
- Ruby
- Scala
- Scheme
- Scheme
- Smalltalk
- SQLite
- Swift
- TCL
- Text
- Unlambda
- VB.NET
- Whitespace
with Ada.Text_IO; use Ada.Text_IO; with Ada.Integer_Text_IO; use Ada.Integer_Text_IO; procedure Test is subtype Small is Integer range 0..99; Input : Small; begin loop Get(Input); if Input = 42 then exit; else Put (Input); New_Line; end if; end loop; end;
global _start section .data buffer dw 0h section .text _start: mov ecx, buffer mov edx, 02h call read mov cx, word [buffer] cmp cx, 3234h je exit cmp ch, 0ah je one_dig jmp two_dig one_dig: mov ecx, buffer mov edx, 02h call write jmp _start two_dig: mov ecx, buffer mov edx, 02h call write mov edx, 01h mov ecx, buffer call read ; read the 0ah mov ecx, buffer call write ; write the 0ah jmp _start exit: mov eax, 01h ; exit() xor ebx, ebx ; errno int 80h read: mov eax, 03h ; read() mov ebx, 00h ; stdin int 80h ret write: mov eax, 04h ; write() mov ebx, 01h ; stdout int 80h ret
.data x: .long 0 s: .string "%d\n\0" .text .global main main: # int main() # { loop: # for (;;) { pushl $x # scanf("%d", &x); pushl $s call scanf addl $8, %esp movl x, %eax # if (x == 42) break; subl $42, %eax jz break pushl x # printf("%d\n", x); pushl $s call printf addl $8, %esp jmp loop # } break: xor %eax, %eax # return 0; ret # }
#!/bin/bash while true do read line if [ $line -eq 42 ] then exit 0 fi echo $line done
/* read the numbers; notice: ech line of the input must be followed by an EOF character */ x = read(); /* multiplication table */ for (i=1; i<=x; ++i) { for (j=1; j<=x; ++j) print i*j, "\t" print "\n" } /* compute the pi number accurately to 10 decimal places */ scale=x print "\npi = ", 4*a(1), "\n" /* factorial */ define f(n) { if (n <= 1) return 1; return n * f(n-1); } print "\n"; print "1! = ", f(1), "\n"; print "5! = ", f(5), "\n"; print x, "! = ", f(x), "\n";
>+[>>,----------[>,----------]+++++[<-------->-]<[>>-<]>+[ -<+++++++[<------>-]<[>>-<]>+[ -<<[>>-<]>+[<<->>->]> ]<+++++++[<++++++>-]>> ]<++++++++[<+++++>-]< [<]<[>>[++++++++++.>]++++++++++.[[-]<]]<]
using System; public class Test { public static void Main() { int n; while ((n = int.Parse(Console.ReadLine()))!=42) Console.WriteLine(n); } }
#include <iostream> using namespace std; // consider removing this line in serious projects int main() { int intNum = 0; cin >> intNum; while (intNum != 42) { cout << intNum << "\n"; cin >> intNum; } return 0; }
#include <iostream> using namespace std; // consider removing this line in serious projects int main() { int intNum = 0; cin >> intNum; while (intNum != 42) { cout << intNum << "\n"; cin >> intNum; } return 0; }
#include <iostream> using namespace std; // consider removing this line in serious projects int main() { auto func = [] () { int intNum = 0; cin >> intNum; while (intNum != 42) { cout << intNum << "\n"; cin >> intNum; } }; func(); return 0; }
(defrule readin ?f<-(initial-fact) => (retract ?f) (assert (number (read))) ) (defrule writeout ?f<-(number ?n)(test (<> ?n 42)) => (retract ?f) (printout t ?n crlf) (assert (initial-fact)) ) (reset) (run) (exit) ; empty line at the end
(defn bottles [n & [capitalize]] (str (if (> n 0) n (if capitalize "No more" "no more")) " bottle" (if (= 1 n) "" "s") " of beer" )) (defn bot-wall [n & cap] (str (bottles n cap) " on the wall")) (defn sing ; Default is 99 times. ([] (sing 99)) ([stock] (doseq [i (range stock -1 -1)] (bot-wall i true) (bottles i) (apply str (if (> i 0) ["Take one down and pass it around, " (bot-wall (dec i))] ["Go to the store and buy some more, " (bot-wall stock)] )))))) (sing)
IDENTIFICATION DIVISION. PROGRAM-ID. IDEONE. ENVIRONMENT DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. 77 n PIC Z9 . PROCEDURE DIVISION. ACCEPT n PERFORM UNTIL n = 42 DISPLAY n ACCEPT n END-PERFORM. STOP RUN.
IDENTIFICATION DIVISION. PROGRAM-ID. IDEONE. ENVIRONMENT DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. 77 n PIC Z9 . PROCEDURE DIVISION. ACCEPT n PERFORM UNTIL n = 42 DISPLAY n ACCEPT n END-PERFORM. STOP RUN.
(loop (let ((a (read))) (when (= a 42) (return)) (princ (format nil "~D~%" a))))
(loop for line = (read-line *standard-input* nil nil) while (not (equal line "42")) do (format t "~A~%" line))
import std.c.stdio; int main() { int x; while (scanf("%d", &x) && x!=42) printf ("%d\n", x); return 0; }
import std.c.stdio; int main() { int x; while (scanf("%d", &x) && x!=42) printf ("%d\n", x); return 0; }
seq { while true do yield stdin.ReadLine () } |> Seq.takeWhile ((<>) "42") |> Seq.iter (printfn "%s")
class FantomSay { Void main(Str[] args) { speech := args.first ?: "Fantom - It's Spookily Good!" width := speech.size bubble := "" bubble += " " + "".padl(width + 2, '_') + "\n" bubble += "< " + speech.justl(width) + " >\n" bubble += " " + "".padl(width + 2, '-') + "\n" ascii := bubble + " \\ \\ .----. \\ / O O | / | / | \\/\\/\\/\\/" echo(ascii) } }
program TEST integer ans do read (*,*) ans if (ans.eq.42) stop write (*,*) ans enddo stop end
package main import "fmt" func main(){ var n int fmt.Scanf("%d",&n) for n!=42 { fmt.Printf("%d\n",n) fmt.Scanf("%d",&n) } }
class Greet { def name Greet(who) { name = who[0].toUpperCase() + who[1..-1] } def salute() { println "Hello $name!" } } g = new Greet('world') // create object g.salute()
PLEASE DO ,1 <- #1 PLEASE DO .4 <- #0 PLEASE DO .5 <- #0 PLEASE DO .99 <- #0 DO COME FROM (30) DO COME FROM (31) DO WRITE IN ,1 DO .1 <- ,1SUB#1 DO .2 <- .4 DO (1000) NEXT DO .4 <- .3~#255 DO (10) NEXT (42) DO .1 <- .1 (20) DO .42 <- "&'&.4~#26'$#1" PLEASE RESUME "?.42$#1"~#3 (10) DO (20) NEXT DO FORGET #1 PLEASE COME FROM (42) PLEASE STASH .1+.2+.3 DO .1 <- .4 DO .2 <- #50 DO (1010) NEXT DO (100) NEXT PLEASE STASH .1+.2+.3 DO .1 <- .99 DO .2 <- #52 DO (1010) NEXT DO (101) NEXT PLEASE GIVE UP (201) DO .3 <- '.3~.3'~#1 PLEASE RESUME "?.3$#2"~#3 (101) DO (201) NEXT DO FORGET #1 (32) PLEASE RETRIEVE .1+.2+.3 (200) DO .3 <- '.3~.3'~#1 PLEASE RESUME "?.3$#2"~#3 (100) DO (200) NEXT DO FORGET #1 DO COME FROM (32) PLEASE RETRIEVE .1+.2+.3 DO (102) NEXT (31) DO .99 <- .4 (202) DO .98 <- '.99~.99'~#1 PLEASE RESUME "?.98$#2"~#3 (102) DO (202) NEXT DO FORGET #1 DO .3 <- !99~#15'$!99~#240' DO .3 <- !3~#15'$!3~#240' DO .2 <- !3~#15'$!3~#240' DO .1 <- .5 DO (1010) NEXT DO .5 <- .2 DO ,1SUB#1 <- .3 PLEASE READ OUT ,1 (30) DO .99 <- .4
/* package whatever; // don't place package name! */ import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ class Ideone { { String s; } }
/* package whatever; // don't place package name! */ import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ class Ideone { { String s; } }
importPackage(java.io); importPackage(java.lang); var reader = new BufferedReader( new InputStreamReader(System['in']) ); while(true) { var line = reader.readLine(); if(line == null || line == "42") { break; } else { System.out.println(line); } }
local read, write = io.read, io.write local num, nl = '*n', '\n' while true do local a = read(num) if a == 42 then return end write(a, nl) end
using System; public class Test { public static Main() : void { def solve() : void { def i = int.Parse(Console.ReadLine()); unless (i == 42) { Console.WriteLine(i); solve(); } } solve(); } }
{ String s; }
proc GetBottleNumber(n: int): string = var bs: string if n == 0: bs = "No more bottles" elif n == 1: bs = "1 bottle" else: bs = $n & " bottles" return bs & " of beer" for bn in countdown(99, 1): var cur = GetBottleNumber(bn) echo(cur, " on the wall, ", cur, ".") echo("Take one down and pass it around, ", GetBottleNumber(bn-1), " on the wall.\n") echo "No more bottles of beer on the wall, no more bottles of beer." echo "Go to the store and buy some more, 99 bottles of beer on the wall."
process.stdin.resume(); process.stdin.setEncoding('utf8'); var remainder = '' process.stdin.on('data', function (chunk) { var lines = chunk.toString().split('\n'); lines.unshift(remainder + lines.shift()); remainder = lines.pop(); lines.forEach(function(line) { if (line === '42') { process.exit(); } process.stdout.write(line+'\n'); }); });
#import <objc/objc.h> #import <objc/Object.h> #import <Foundation/Foundation.h> @interface TestObj : NSObject { int num; } - (void)foo; @end @implementation TestObj - (void)foo { } int main() { id obj = [[TestObj alloc] init]; [obj foo]; return 0; } @end
#import <objc/objc.h> #import <objc/Object.h> #import <Foundation/Foundation.h> @interface TestObj : NSObject { int num; } - (void)foo; @end @implementation TestObj - (void)foo { } int main() { id obj = [[TestObj alloc] init]; [obj foo]; return 0; } @end
while true do print_int n; done;
x = [1 2 3 4 5 6 7 8 9 10]; y1 = [.16 .08 .04 .02 .013 .007 .004 .002 .001 .0008 ]; y2 = [.16 .07 .03 .01 .008 .003 .0008 .0003 .00007 .00002 ]; semilogy(x,y1,'-bo;y1;',x,y2,'-kx;y2;'); title('Plot title'); xlabel('X Axis'); ylabel('Y Axis'); print out.png
functor import Application System define {System.showInfo 'Hello World!'} end
program ideone; var x: integer; begin repeat readln(x); if x<>42 then writeln(x); until x=42 end.
program ideone; var x:byte; begin readln(x); while x<>42 do begin writeln(x); readln(x) end end.
n = int(raw_input()) while n != 42: print n n = int(raw_input())
f <- file("stdin") open(f) while(length(n <- as.integer(readLines(f,n=1))) > 0) { if (n == 42) { break; } write(n, stdout()) }
(define (do_it n) (define (print_it n) (display n) (newline)) (cond ((not(= n 42)) (print_it n) (do_it (read))) )) (do_it (read))
(define (do_it n) (define (print_it n) (display n) (newline)) (cond ((not(= n 42)) (print_it n) (do_it (read))) )) (do_it (read))
|c number| [ number:=0. [ (c := stdin next) asciiValue ~= 10 ] whileTrue: [number := (number * 10) + (c asciiValue) - 48.]. number ~= 42 ] whileTrue: [Transcript show: number printString; cr.] !
create table tbl(str varchar(20)); insert into tbl values('Hello world!'); select * from tbl;
while let line = readLine() { let n = Int(line) if n == 42 { break } print(n!) }
set num [gets stdin] while { $num != 42 } { puts $num; set num [gets stdin] }
```s``sii`ki ``s``s`ks ``s``s`ks``s`k`s`kr ``s`k`si``s`k`s`k `d````````````.H.e.l.l.o.,. .w.o.r.l.d.! k k `k``s``s`ksk`k.*
Imports System Public Class Test Public Shared Sub Main() Dim n As Integer n = Console.ReadLine Do While n <> 42 System.Console.WriteLine(n) n = Console.ReadLine Loop End Sub End Class