Login
|
Signup
langref.org
-
ruby
,
erlang
,
cpp
,
fantom
...
add..
all
clojure
fsharp
go
groovy
haskell
java
ocaml
perl
php
python
scala
Home
All
Solved
Unsolved
Strings
Numbers
Regex
Lists
Maps
Structure
Files
Dates
OOP
Networking
XML
Algorithms
Misc
Parallel
View Problem
Structure
Loops
Perform an action a fixed number of times (FOR)
Display the string
"Hello"
five times like
"HelloHelloHelloHelloHello"
ruby
puts "Hello"*5
puts "Hello"*5
ruby
5.times { print "Hello" }
5.times { print "Hello" }
erlang
dotimes(5, fun () -> io:format("Hello") end).
-module(dotimes).
-export([start/0]).
start() ->
dotimes(5, fun () -> io:format("Hello") end).
dotimes(0, _) -> true;
dotimes(N, Action) -> Action(), dotimes(N - 1, Action).
erlang
lists:foreach(fun (_) -> io:format("Hello") end, lists:seq(1, 5)).
-module(dotimes).
-export([start/0]).
start() ->
lists:foreach(fun (_) -> io:format("Hello") end, lists:seq(1, 5)).
cpp
C++/CLI .NET 2.0
for(int i = 0; i < 5; ++i) Console::Write("Hello");
using namespace System;
int main()
{
for(int i = 0; i < 5; ++i) Console::Write("Hello");
}
cpp
C++/CLI .NET 2.0
for(int i = 5; i > 0; --i) Console::Write("Hello");
using namespace System;
int main()
{
for(int i = 5; i > 0; --i) Console::Write("Hello");
}
cpp
dotimes(5, hello);
#include <iostream>
void dotimes(int n, void(*f)()) { if (n != 0) { f(); dotimes(--n, f); } }
void hello() { std::cout << "Hello"; }
int main()
{
dotimes(5, hello);
}
cpp
fill_n(ostream_iterator<string>(cout), 5, "Hello");
#include <iostream>
#include <algorithm>
#include <iterator>
using namespace std;
int main()
{
fill_n(ostream_iterator<string>(cout), 5, "Hello");
}
fantom
5.times { Env.cur.out.print("Hello") }
class SolutionXX
{
Void main()
{
5.times { Env.cur.out.print("Hello") }
}
}
fantom
for (i := 0; i < 5; i++)
Env.cur.out.print("Hello")
class SolutionXX
{
Void main()
{
for (i := 0; i < 5; i++)
Env.cur.out.print("Hello")
}
}
fantom
(1..5).each { Env.cur.out.print("Hello") }
class SolutionXX
{
Void main()
{
(1..5).each { Env.cur.out.print("Hello") }
}
}
csharp
string text = "Hello";
for (int i = 0; i < 5; i++)
{
Console.Write(text);
}
string text = "Hello";
for (int i = 0; i < 5; i++)
{
Console.Write(text);
}
Submit a new solution for
ruby
,
erlang
,
cpp
,
fantom
...
There are 25 other solutions in
additional
languages (
clojure
,
fsharp
,
groovy
,
haskell
...)