Use key to get itself
-
Is
if
not a flow-control statement?
-
I think that Go really gets this one right. Any new variables you introduce after the flow-control keyword are scoped to the block that follows.
if
(both branches),for
, andswitch
.The TypeSwitchGuard may include a short variable declaration. When that form is used, the variable is declared at the beginning of the implicit block in each clause. In clauses with a case listing exactly one type, the variable has that type; otherwise, the variable has the type of the expression in the TypeSwitchGuard.
-
It is; I've never seen anyone define a variable in an
if
statement though.
-
-
C#6 hasn't been officially released yet (only preview), so it doesn't count
-
a variable in an if statement
Works nicely with pointers in C++:
System &sys = /*...*/; if(SubSystem *subsys = sys.get_optional_subsystem()) { // do stuff with 'subsys'... } // 'subsys' is out of scope now...
-
Works nicely with pointers in C++:
C# requires the result of the expression to bebool
. And it won't coerce.
-
C# requires the result of the expression to be bool. And it won't coerce.
:fail.pfx:
-
The braces are implied for flow-control statements, and for scoping purposes, the flow-control statement itself is scoped to the (implied) braces.
Up to the point of reading that I'd been ignorant-but-curious towards C#.
-
And now you are...? Hot and bothered towards C#? Itching and burning for C#?
-
Itching and burning for C#
That one. Yeah, definitely that one.
googles
Wait. No it isn't.
-
Ask your doctor if a C# prescription is right for you.
-
Wait, so "for (int i = 0; i < 3; ++i) dosomething(i);" (I'm assuming that's valid C#, as well as C++) means i survives after the 'for'? If so, that's just wrong. If no, then the previous example is just wrong.
What's wrong is the lack of braces.
-
Also, why are there parentheses around two statements and an expression? That's not what parentheses are normally around!
-
(I'm assuming that's valid C#, as well as C++)
Also, why are there parentheses around two statements and an expression?
Because it indicates that these are subordinate to the main thrust of the argument.