Sync
This commit is contained in:
parent
6f050a029e
commit
776bba907c
3887 changed files with 59894 additions and 7280 deletions
|
|
@ -0,0 +1,7 @@
|
|||
x = 1
|
||||
If x
|
||||
MsgBox, x is %x%
|
||||
Else If x > 1
|
||||
MsgBox, x is %x%
|
||||
Else
|
||||
MsgBox, x is %x%
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
x = 2
|
||||
y = 1
|
||||
var := x > y ? 2 : 3
|
||||
MsgBox, % var
|
||||
|
||||
===while (looping if)===
|
||||
<lang AutoHotkey>While (A_Index < 3) {
|
||||
MsgBox, %A_Index% is less than 3
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
IF x == 1
|
||||
SomeFunc1()
|
||||
ELSEIF x == 2
|
||||
SomeFunc2()
|
||||
ELSE
|
||||
SomeFunc()
|
||||
ENDIF
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
DO CASE
|
||||
CASE x == 1
|
||||
SomeFunc1()
|
||||
CASE x == 2
|
||||
SomeFunc2()
|
||||
OTHERWISE
|
||||
SomeFunc()
|
||||
ENDCASE
|
||||
49
Task/Conditional-structures/D/conditional-structures.d
Normal file
49
Task/Conditional-structures/D/conditional-structures.d
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
void main() {
|
||||
enum int i = 5;
|
||||
|
||||
// "static if" for various static checks:
|
||||
static if (i == 7) {
|
||||
// ...
|
||||
} else {
|
||||
//...
|
||||
}
|
||||
|
||||
// is(T == U) checks if type T is U.
|
||||
static if (is(typeof(i) == int)) {
|
||||
// ...
|
||||
} else {
|
||||
// ...
|
||||
}
|
||||
|
||||
// D switch is improved over C switch:
|
||||
switch (i) {
|
||||
case 0:
|
||||
break; // Silent fallthrough is forbidden.
|
||||
case 1:
|
||||
goto case; // Explicit fallthrough.
|
||||
case 2:
|
||||
// Empty cases don't require an explicit fallthrough.
|
||||
case 3:
|
||||
return;
|
||||
case 4, 5, 7: // Multiple cases.
|
||||
break;
|
||||
case 8: .. case 15: // Inclusive interval.
|
||||
goto case 3;
|
||||
default: // Default case is required.
|
||||
break;
|
||||
}
|
||||
|
||||
enum Colors { yellow, blue, brown, green }
|
||||
immutable c = Colors.blue;
|
||||
|
||||
// "final switch" is safer, for enums (and in future other values,
|
||||
// like Algebraic), because all cases must be present.
|
||||
// with() is handy to avoid repeating "Colors." for each case.
|
||||
final switch (c) with (Colors) {
|
||||
case yellow: break;
|
||||
case blue: break;
|
||||
case brown, green: break;
|
||||
// case yellow: .. case brown: // Forbidden in final switches.
|
||||
// default: // Forbidden in final switches.
|
||||
}
|
||||
}
|
||||
|
|
@ -3,6 +3,7 @@ dispatcher[0]=foo # Not foo(): we bind the dictionary entry to the function's o
|
|||
# NOT to the results returned by an invocation of the function
|
||||
dispatcher[1]=bar
|
||||
dispatcher[2]=baz # foo,bar, baz, and boz are defined functions.
|
||||
|
||||
# Then later
|
||||
results = dispatcher.get(x, boz)() # binding results to a name is optional
|
||||
# or with no "default" case:
|
||||
|
|
|
|||
|
|
@ -0,0 +1,8 @@
|
|||
# The above, but with a dict literal
|
||||
dispatcher = {
|
||||
0: foo,
|
||||
1: bar,
|
||||
2: baz,
|
||||
}
|
||||
# ...
|
||||
results = dispatcher.get(x, boz)()
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
# Or without the temp variable
|
||||
# (it's up to the reader to decide how "pythonic" this is or isn't)
|
||||
results = {
|
||||
0: foo,
|
||||
1: bar,
|
||||
2: baz,
|
||||
}.get(x, boz)()
|
||||
|
|
@ -1,12 +1,17 @@
|
|||
<xsl:choose>
|
||||
<xsl:when test="condition1">
|
||||
<!-- executed if condition1 evaluates to true -->
|
||||
<!-- included if condition1 evaluates to true (like C `if`) -->
|
||||
</xsl:when>
|
||||
<xsl:when test="condition2">
|
||||
<!-- executed if condition2 evaluates to true -->
|
||||
<!-- included if all previous conditions evaluated to false and
|
||||
condition2 evaluates to true (like C `else if`) -->
|
||||
</xsl:when>
|
||||
<-- etc. -->
|
||||
<--
|
||||
...
|
||||
-->
|
||||
<xsl:otherwise>
|
||||
<!-- optional catch-all processing, like C's else or default -->
|
||||
<!-- included if all previous conditions evaluated to false
|
||||
(like C `else`) -->
|
||||
<!-- (The `otherwise` element is optional) -->
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,11 @@
|
|||
@attrib = 'false'
|
||||
position() != last()
|
||||
not( false() )
|
||||
boolean( $param )
|
||||
<xsl:if test="@attrib = 'foo'">...</xsl:if>
|
||||
<xsl:if test="position() != last()">...</xsl:if>
|
||||
<xsl:if test="not(false())">...</xsl:if>
|
||||
|
||||
<!-- Some XPath expressions must be escaped. -->
|
||||
<xsl:if test='contains(node, "stuff") and (position() > first())'>...</xsl:if>
|
||||
|
||||
<!-- The following two examples are synonymous because the test attribute is
|
||||
implicitly converted to boolean. -->
|
||||
<xsl:if test="boolean($expr)">...</xsl:if>
|
||||
<xsl:if test="$expr">...</xsl:if>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue