Last active
December 28, 2015 03:19
-
-
Save aeg/7434025 to your computer and use it in GitHub Desktop.
文字列を繰り返す
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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