Skip to content

Commit 5094f5f

Browse files
committed
generate
1 parent 403d47b commit 5094f5f

File tree

2 files changed

+237
-92
lines changed

2 files changed

+237
-92
lines changed

public/1.6/book/if.html

Lines changed: 69 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -186,73 +186,106 @@
186186

187187

188188
<h1 class="title">if</h1>
189-
<p>Rust’s take on <code>if</code> is not particularly complex, but it’s much more like the
190-
<code>if</code> you’ll find in a dynamically typed language than in a more traditional
191-
systems language. So let’s talk about it, to make sure you grasp the nuances.</p>
189+
<!-- % if -->
192190

193-
<p><code>if</code> is a specific form of a more general concept, the ‘branch’. The name comes
194-
from a branch in a tree: a decision point, where depending on a choice,
195-
multiple paths can be taken.</p>
191+
<!-- Rust’s take on `if` is not particularly complex, but it’s much more like the -->
196192

197-
<p>In the case of <code>if</code>, there is one choice that leads down two paths:</p>
193+
<!-- `if` you’ll find in a dynamically typed language than in a more traditional -->
194+
195+
<!-- systems language. So let’s talk about it, to make sure you grasp the nuances. -->
196+
197+
<p>Rustにおける <code>if</code> の扱いはさほど複雑ではありませんが、伝統的なシステムプログラミング言語のそれに比べて、
198+
動的型付け言語でみられる <code>if</code> にずっと近いものになっています。そのニュアンスをしっかり理解できるよう、
199+
さっそく説明していきましょう。</p>
200+
201+
<!-- `if` is a specific form of a more general concept, the ‘branch’. The name comes -->
202+
203+
<!-- from a branch in a tree: a decision point, where depending on a choice, -->
204+
205+
<!-- multiple paths can be taken. -->
206+
207+
<p><code>if</code> は一般化されたコンセプト、「分岐(branch)」の特別な形式です。この名前は木の枝(branch)を由来とし:
208+
取りうる複数のパスから、選択の決定を行うポイントを表します。</p>
209+
210+
<!-- In the case of `if`, there is one choice that leads down two paths: -->
211+
212+
<p><code>if</code> の場合は、続く2つのパスから1つを選択します。</p>
198213
<span class='rusttest'>fn main() {
199214
let x = 5;
200215

201216
if x == 5 {
202-
println!(&quot;x is five!&quot;);
217+
// println!(&quot;x is five!&quot;);
218+
println!(&quot;x は 5 です!&quot;);
203219
}
204220
}</span><pre class='rust rust-example-rendered'>
205221
<span class='kw'>let</span> <span class='ident'>x</span> <span class='op'>=</span> <span class='number'>5</span>;
206222

207223
<span class='kw'>if</span> <span class='ident'>x</span> <span class='op'>==</span> <span class='number'>5</span> {
208-
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>&quot;x is five!&quot;</span>);
224+
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>&quot;x は 5 です!&quot;</span>);
209225
}</pre>
210226

211-
<p>If we changed the value of <code>x</code> to something else, this line would not print.
212-
More specifically, if the expression after the <code>if</code> evaluates to <code>true</code>, then
213-
the block is executed. If it’s <code>false</code>, then it is not.</p>
227+
<!-- If we changed the value of `x` to something else, this line would not print. -->
228+
229+
<!-- More specifically, if the expression after the `if` evaluates to `true`, then -->
214230

215-
<p>If you want something to happen in the <code>false</code> case, use an <code>else</code>:</p>
231+
<!-- the block is executed. If it’s `false`, then it is not. -->
232+
233+
<p>仮に <code>x</code> を別の値へと変更すると、この行は表示されません。より正確に言うなら、
234+
<code>if</code> のあとにくる式が <code>true</code> に評価された場合に、ブロックが実行されます。
235+
<code>false</code> の場合、ブロックは実行されません。</p>
236+
237+
<!-- If you want something to happen in the `false` case, use an `else`: -->
238+
239+
<p><code>false</code> の場合にも何かをしたいなら、 <code>else</code> を使います:</p>
216240
<span class='rusttest'>fn main() {
217241
let x = 5;
218242

219243
if x == 5 {
220-
println!(&quot;x is five!&quot;);
244+
// println!(&quot;x is five!&quot;);
245+
println!(&quot;x は 5 です!&quot;);
221246
} else {
222-
println!(&quot;x is not five :(&quot;);
247+
// println!(&quot;x is not five :(&quot;);
248+
println!(&quot;x は 5 ではありません :(&quot;);
223249
}
224250
}</span><pre class='rust rust-example-rendered'>
225251
<span class='kw'>let</span> <span class='ident'>x</span> <span class='op'>=</span> <span class='number'>5</span>;
226252

227253
<span class='kw'>if</span> <span class='ident'>x</span> <span class='op'>==</span> <span class='number'>5</span> {
228-
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>&quot;x is five!&quot;</span>);
254+
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>&quot;x は 5 です!&quot;</span>);
229255
} <span class='kw'>else</span> {
230-
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>&quot;x is not five :(&quot;</span>);
256+
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>&quot;x は 5 ではありません :(&quot;</span>);
231257
}</pre>
232258

233-
<p>If there is more than one case, use an <code>else if</code>:</p>
259+
<!-- If there is more than one case, use an `else if`: -->
260+
261+
<p>場合分けが複数あるときは、 <code>else if</code> を使います:</p>
234262
<span class='rusttest'>fn main() {
235263
let x = 5;
236264

237265
if x == 5 {
238-
println!(&quot;x is five!&quot;);
266+
// println!(&quot;x is five!&quot;);
267+
println!(&quot;x は 5 です!&quot;);
239268
} else if x == 6 {
240-
println!(&quot;x is six!&quot;);
269+
// println!(&quot;x is six!&quot;);
270+
println!(&quot;x は 6 です!&quot;);
241271
} else {
242-
println!(&quot;x is not five or six :(&quot;);
272+
// println!(&quot;x is not five or six :(&quot;);
273+
println!(&quot;x は 5 でも 6 でもありません :(&quot;);
243274
}
244275
}</span><pre class='rust rust-example-rendered'>
245276
<span class='kw'>let</span> <span class='ident'>x</span> <span class='op'>=</span> <span class='number'>5</span>;
246277

247278
<span class='kw'>if</span> <span class='ident'>x</span> <span class='op'>==</span> <span class='number'>5</span> {
248-
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>&quot;x is five!&quot;</span>);
279+
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>&quot;x は 5 です!&quot;</span>);
249280
} <span class='kw'>else</span> <span class='kw'>if</span> <span class='ident'>x</span> <span class='op'>==</span> <span class='number'>6</span> {
250-
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>&quot;x is six!&quot;</span>);
281+
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>&quot;x は 6 です!&quot;</span>);
251282
} <span class='kw'>else</span> {
252-
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>&quot;x is not five or six :(&quot;</span>);
283+
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>&quot;x は 5 でも 6 でもありません :(&quot;</span>);
253284
}</pre>
254285

255-
<p>This is all pretty standard. However, you can also do this:</p>
286+
<!-- This is all pretty standard. However, you can also do this: -->
287+
288+
<p>全くもって普通ですね。しかし、次のような使い方もできるのです:</p>
256289
<span class='rusttest'>fn main() {
257290
let x = 5;
258291

@@ -270,7 +303,9 @@ <h1 class="title">if</h1>
270303
<span class='number'>15</span>
271304
}; <span class='comment'>// y: i32</span></pre>
272305

273-
<p>Which we can (and probably should) write like this:</p>
306+
<!-- Which we can (and probably should) write like this: -->
307+
308+
<p>次のように書くこともできます(そして、大抵はこう書くべきです):</p>
274309
<span class='rusttest'>fn main() {
275310
let x = 5;
276311

@@ -280,9 +315,14 @@ <h1 class="title">if</h1>
280315

281316
<span class='kw'>let</span> <span class='ident'>y</span> <span class='op'>=</span> <span class='kw'>if</span> <span class='ident'>x</span> <span class='op'>==</span> <span class='number'>5</span> { <span class='number'>10</span> } <span class='kw'>else</span> { <span class='number'>15</span> }; <span class='comment'>// y: i32</span></pre>
282317

283-
<p>This works because <code>if</code> is an expression. The value of the expression is the
284-
value of the last expression in whichever branch was chosen. An <code>if</code> without an
285-
<code>else</code> always results in <code>()</code> as the value.</p>
318+
<!-- This works because `if` is an expression. The value of the expression is the -->
319+
320+
<!-- value of the last expression in whichever branch was chosen. An `if` without an -->
321+
322+
<!-- `else` always results in `()` as the value. -->
323+
324+
<p>これが出来るのは <code>if</code> が式であるためです。その式の値は、選択された分岐中の最後の式の値となります。
325+
<code>else</code> のない <code>if</code> では、その値は常に <code>()</code> となります。</p>
286326

287327
<script type="text/javascript">
288328
window.playgroundUrl = "https://play.rust-lang.org";

0 commit comments

Comments
 (0)