JanetDocsPlaygroundI'm feeling luckyGitHub sign in

repeat



    macro
    boot.janet on line 512, column 1

    (repeat n & body)

    Evaluate body n times. If n is negative, body will be evaluated 0 
    times. Evaluates to nil.


3 examplesSign in to add an example
Loading...
# repeat is about _side-effects_, since it returns nil.
# You'll need to use a mutable collection if you want to
# use repeat to add repeated items to a collection:
(var coll @["Y" "Z"]) #=> @["Y" "Z"]
(repeat 3 (array/push coll "A")) #=> nil
coll
# Returns:
@["Y" "Z" "A" "A" "A"]

# You can use map if the whole collection consists
# of these repetitions:
(map (fn [_] "A") (range 3))
# Returns:
@["A" "A" "A"]
semperosPlayground
(repeat 12 (-> 12 os/cryptorand pp))

# => @"\xA7li[ \xED\xD2\xF7O\xD6\x15="
# => @">\"-w+\x04\x1C\xC1KG\x9C\xE4"
# => @"\x06b\f\xBD\x12\x19\xB6\x1A\xCA\xB9[\x85"
# => @"\xBE`R\t\x13\x81\xED\x9D#\xD0\x11!"
# => @"\xE2\xC1\xD8\x7F\\\xA7\x84\xC0\v\x8B'\x98"
# => @"\xD6\x0Fz\x86\xE2\xB2\x1D}\xC6'{\xB5"
# => @"\x9D\x97\xA1\x07i\x9FW\x83h4n2"
# => @"d\x8E\xB8\xBA \xA6\x9C\f\xC6\xAD{g"
# => @"\r\xB5\xF84#\xB8c~V\xD7d>"
# => @"\xBB\x19\xB2\xDC\x8B\xD9\x7F\xDC\xBE\f\x88\xE3"
# => @"w\xB50\xF9\xFD\xEB\x1D\xFF:j]\xB8"
# => @"\x8F$\xEBKL~\xFD\t\xA8\xD1\x8C\xC5"
# => nil
jgartePlayground
(repeat 3 (print "HO"))
# => prints
# HO
# HO
# HO
pepePlayground