-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Break Statement | ||
|
||
=begin | ||
Pattern 1: | ||
1 2 3 4 5 | ||
1 2 3 4 5 | ||
1 2 3 4 5 | ||
1 2 3 4 5 | ||
1 2 3 4 5 | ||
Pattern 2 by modifying Pattern 1 & using break: | ||
1 2 | ||
1 2 | ||
1 2 | ||
1 2 | ||
1 2 | ||
=end | ||
|
||
# Pattern 1 | ||
for r in 1..5 | ||
for c in 1..5 | ||
print "#{c}" | ||
end | ||
print"\n" | ||
end | ||
|
||
# Pattern 2 | ||
for r in 1..5 | ||
for c in 1..5 | ||
print "#{c}" | ||
break if c==2 | ||
end | ||
print"\n" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Next & Redo Statement | ||
|
||
# Next statement | ||
for i in 0..5 | ||
if i < 2 | ||
next | ||
end | ||
puts "The value of local variable i = #{i}" | ||
end | ||
|
||
# Redo statement | ||
for i in 0..5 | ||
if i < 2 | ||
puts "The value of local variable i = #{i}" | ||
redo | ||
end | ||
end |