Skip to content

Instantly share code, notes, and snippets.

@keizo042
Created March 5, 2014 10:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save keizo042/9364719 to your computer and use it in GitHub Desktop.
Save keizo042/9364719 to your computer and use it in GitHub Desktop.
九九を書いてみた。けどifのところが気持ち悪い。
(1 to 10)foreach(
x => (1 to 10)foreach(
y =>if(y !=10) print(x * y+ "\t") else println(x *y + "\t")
)
)
@kmizu
Copy link

kmizu commented Mar 5, 2014

こんにちは。if使わないように書き換えてみました。

{x => ... }

形式の場合、...部分に複数の式を並べて書くことができるのがミソです。

https://gist.github.com/kmizu/9364793

@keizo042
Copy link
Author

keizo042 commented Mar 5, 2014

そちらのほうが読みやすくて無駄のない良いコードですね。
{}と()の扱いの違いを把握する必要がありそうです。
ありがとうございます。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment