-
-
Notifications
You must be signed in to change notification settings - Fork 29
/
switch.mon
44 lines (37 loc) · 980 Bytes
/
switch.mon
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// A simple test-function for switch-statements.
function test( name ) {
// Did we match?
m = false;
switch( name ) {
case /^steve$/ , /^STEVE$/i {
printf("Hello Steve - we matched you via a regexp\n");
m = true;
}
case "St" + "even" {
printf("Hello SteveN, you were matched via an expression\n" );
m = true;
}
case 3, 6, 9 {
printf("Hello multiple of three, we matched you literally: %d\n", int(name));
m = true;
}
default {
printf("Default case: %s\n", string(name) );
}
}
// Show we matched, if we did.
if ( m ) { printf( "\tMatched!\n"); }
}
// Test the switch statement
test( "Steve" ); // Regexp match
test( "steve" ); // Regexp match
test( "Steven" ); // Literal match
test( 3 ); // Literal match
// Unhandled/Default cases
test( "Bob" );
test( false );
// Try some other numbers - only one will match
foreach number in 1..10 {
test(number);
}
printf( "All done\n" );