@@ -251,36 +251,38 @@ $(GNAME ElseStatement):
251
251
$(PSSCOPE)
252
252
)
253
253
254
- $(P *Expression* is evaluated and must have a type that
255
- can be converted to a boolean. If it's `true` the
256
- $(I ThenStatement) is transferred to, else the $(I ElseStatement)
257
- is transferred to.)
258
-
259
- $(P The $(I ElseStatement) is associated with the innermost if
254
+ $(P If there is a declared *Identifier* variable, it is evaluated.
255
+ Otherwise, *Expression* is evaluated. The result is converted to a
256
+ boolean, using $(DDSUBLINK spec/operatoroverloading, cast, `opCast!bool()`)
257
+ if the method is defined.
258
+ If the boolean is `true`, the $(I ThenStatement) is transferred
259
+ to, otherwise the $(I ElseStatement) is transferred to.)
260
+
261
+ $(P The $(I ElseStatement) is associated with the innermost `if`
260
262
statement which does not already have an associated $(I ElseStatement).)
261
263
262
- $(P If an $(D auto) $(I Identifier) is provided, it is declared and
263
- initialized
264
- to the value
265
- and type of the *Expression*. Its scope extends from when it is
266
- initialized to the end of the $(I ThenStatement).)
264
+ $(PANEL
265
+ When an $(I Identifier) form of *IfCondition* is used, a
266
+ variable is declared with that name and initialized to the
267
+ value of the *Expression*.
268
+
269
+ * If $(D auto) $(I Identifier) is provided, the type of the variable
270
+ is the same as *Expression*.
267
271
268
- $(P If a $(I TypeCtors) $(I Identifier) is provided, it is declared
269
- to be of the type specified by $(I TypeCtors)
270
- and is initialized with the value of the *Expression*.
271
- Its scope extends from when it is
272
- initialized to the end of the $(I ThenStatement).)
272
+ * If $(I TypeCtors) $(I Identifier) is provided, the variable is
273
+ declared to be the type of *Expression* but with $(I TypeCtors) applied.
273
274
274
- $(P If a $(I Declarator) is provided, it is declared and
275
- initialized
276
- to the value
277
- of the *Expression*. Its scope extends from when it is
278
- initialized to the end of the $(I ThenStatement).)
275
+ * If the $(I BasicType) form is provided, it declares the type of the
276
+ variable as it would for a normal
277
+ $(DDSUBLINK spec/declaration, variable-declarations, variable declaration).
279
278
279
+ $(P The scope of the variable is the *ThenStatement* only.)
280
+
281
+ $(SPEC_RUNNABLE_EXAMPLE_RUN
280
282
---
281
283
import std.regex;
282
- ...
283
- if (auto m = std.regex. matchFirst("abcdef", "b(c)d"))
284
+
285
+ if (auto m = matchFirst("abcdef", "b(c)d"))
284
286
{
285
287
writefln("[%s]", m.pre); // prints [a]
286
288
writefln("[%s]", m.post); // prints [ef]
@@ -289,10 +291,13 @@ if (auto m = std.regex.matchFirst("abcdef", "b(c)d"))
289
291
}
290
292
else
291
293
{
292
- writeln(m.post); // Error: undefined identifier 'm'
294
+ writeln("no match");
295
+ //writeln(m.post); // Error: undefined identifier 'm'
293
296
}
294
- writeln(m.pre); // Error: undefined identifier 'm'
297
+ // writeln(m.pre); // Error: undefined identifier 'm'
295
298
---
299
+ )
300
+ )
296
301
297
302
$(H2 $(LEGACY_LNAME2 WhileStatement, while-statement, While Statement))
298
303
0 commit comments