Logo

Programming-Idioms

Loop to execute some code a constant number of times
Implementation
Kotlin

Implementation edit is for fixing errors and enhancing with metadata. Please do not replace the code below with a different implementation.

Instead of changing the code of the snippet, consider creating another Kotlin implementation.

Be concise.

Be useful.

All contributions dictatorially edited by webmasters to match personal tastes.

Please do not paste any copyright violating material.

Please try to avoid dependencies to third-party libraries and frameworks.

Other implementations
for(int i=0;i<10;i++)
  System.out.println("Hello");
for _ in range(10):
    print("Hello")
for ($i = 0; $i < 10; $i++) {
    echo 'Hello' . PHP_EOL;
}
import "fmt"
for i := 0; i < 10; i++ {
	fmt.Println("Hello")
}
for (let i = 0; i < 10; i++) {
  console.log("Hello");
}
#include <stdio.h>
for (int i = 0; i < 10; i++) {
    printf("Hello\n");
}
using System;
for (int i = 0; i < 10; i++)
{
    Console.WriteLine("Hello");
}
10.times do
  puts "Hello"
end
#include <iostream>
using namespace std;
for (int i = 0; i < 10; ++i)
  cout << "Hello\n";
import Control.Monad
replicateM_ 10 $ putStrLn "Hello"
(define (hellos i)
        (if (> i 0)    
            (begin
                (display "Hello")
                (newline)
                (hellos (- i 1)))))
(hellos 10)
print("Hello\n" * 10);
print "Hello\n" for 1 .. 10;
for _ in 0..10 { println!("Hello"); }
import std.stdio;
foreach(i; 0..10)
  writeln("Hello");
var
  i: integer;
begin
  for i:=1 to 10 do
    WriteLn('Hello');
end;
(dotimes [_ 10]
  (println "Hello"))
1..10 |> Enum.each(fn _ -> IO.puts "Hello" end)
10.times { puts 'Hello' }
lists:foreach(
  fun(_) ->
    io:format("Hello~n")
  end, lists:seq(1, 10)).
say "Hello" for 1 .. 10;
with Ada.Text_IO;
use Ada.Text_IO;
for I in 1 .. 10 loop
  Put_Line ("Hello");
end loop;
for i=1, 10 do
	print('Hello')
end
(0 until 10).foreach( _ => println("Hello"))
import std.stdio : writeln;
import std.range : iota;
import std.algorithm.iteration : each;
iota(0,10).each!(a => "Hello".writeln);
for (NSInteger i=0;i<10;i++){
NSLog(@"Hello");
}
(loop repeat 10 do (write-line "Hello"))
puts "Hello\n" * 10
print "Hello\n" x 10;
program main
  implicit none
  integer :: i
  do i=1,10
    write (*,'(A)') "Hello"
  end do
end program main
(0..9).forEach {
    println("Hello")
}
let rec n_hellos
    (n : int)
  : unit =
  if n = 0 then
    ()
  else
    (print_endline "Hello";
    n_hellos (n-1))

n_hello_worlds 10
let count = 0;
while (count < 10) {
  count++; 
  console.log('Hello');
};
Imports System
For x = 1 To 10
    Console.WriteLine("Hello")
Next x
print("Hello\n"*10)
IDENTIFICATION DIVISION.
PROGRAM-ID. hello 10 times.
PROCEDURE DIVISION.
PERFORM 10 TIMES
   DISPLAY "Hello"
END-PERFORM
STOP RUN.
foreach(range(1, 10) as $i)
  echo 'Hello'. PHP_EOL;
[...Array(10)].forEach(() => console.log('Hello'))
10.times {
    println 'Hello'
}​
System.out.print("Hello\n".repeat(10));
print!("{}", "Hello\n".repeat(10));
:- initialization(main).
main :- loop(10).

loop(0).
loop(N) :- N>0, write('Hello') , nl, N1 = N - 1, loop(N1).
println("Hello\n"*10)
print(("Hello\n"):rep(10))
print(string.rep("Hello\n", 10))
(for-each (lambda (x) (display "Hello\n")) (iota 10))
local i = 0
repeat
	i = i + 1
	print("Hello")
until i == 10
console.log( 'Hello\n'.repeat(10) )
(do ((i 0 (+ i 1)))
    ((= i 10))
  (display "Hello")
  (newline))
import "fmt"
import "strings"
fmt.Println(strings.Repeat("Hello\n", 10))
10 timesRepeat: [Transcript showln: 'Hello'].
using System;
using System.Linq;
Console.WriteLine(string.Join(Environment.NewLine, Enumerable.Repeat("Hello", 10)));
using System;
using System.Linq;
Console.WriteLine( string.Concat(Enumerable.Repeat("Hello\n", 10)) );
for(x in 1..10) {
     println("Hello")
}
for (var i = 0; i < 10; i++)
  print("Hello");
i = 0
while i < 10:
    print('Hello')
    i += 1
for(int count = 1; count < 11; count++) {
	System.out.printf("%s%n", "Hello");
}
import "fmt"
for range 10 {
	fmt.Println("Hello")
}