Skip to content

Instantly share code, notes, and snippets.

@aeg
Last active December 28, 2015 03:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aeg/7434025 to your computer and use it in GitHub Desktop.
Save aeg/7434025 to your computer and use it in GitHub Desktop.
文字列を繰り返す
// Case #1
// 文字列を繰り返すときには * 演算子を使う。繰り返す回数を指定します。
def s = 'Go! '
assert s * 3 == 'Go! Go! Go! '
// Case #2
// 当たり前ですが、繰り返し回数の指定は変数も使えます
(1..5).each { len -> println '+' * len }
/* 結果
+
++
+++
++++
+++++
*/
// Case #3
// 0回繰り返すと空文字になります
assert "Go! " * 0 == ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment