Skip to content

Commit 7065538

Browse files
committed
add documentation for using switch without a control expression
1 parent 7fdd21b commit 7065538

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
score = 76
2+
grade = switch
3+
when 90 <= score then 'A'
4+
when 80 <= score < 90 then 'B'
5+
when 70 <= score < 80 then 'C'
6+
when 60 <= score < 70 then 'D'
7+
when score < 60 then 'F'
8+
# grade == 'C'

documentation/index.html.erb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,11 @@ Expressions
823823
</p>
824824
<%= code_for('switch') %>
825825

826+
<p>
827+
Switch statements can also be used without a control expression, turning them in to a cleaner alternative to if/else chains.
828+
</p>
829+
<%= code_for('switch_with_no_expression') %>
830+
826831
<p>
827832
<span id="try" class="bookmark"></span>
828833
<b class="header">Try/Catch/Finally</b>

0 commit comments

Comments
 (0)