Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update 03_Ranges.md #204

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions examples/02_control_flow/03_Ranges.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,17 @@ fun main() {
}
print(" ")

for(i in 2..8 step 2) { // 3
for(i in 0..<3) { // 3
print(i)
}
print(" ")

for (i in 3 downTo 0) { // 4
for(i in 2..8 step 2) { // 4
print(i)
}
print(" ")

for (i in 3 downTo 0) { // 5
print(i)
}
print(" ")
Expand All @@ -31,8 +36,9 @@ fun main() {

1. Iterates over a range starting from 0 up to 3 (inclusive). Like 'for(i=0; i<=3; ++i)' in other programming languages (C/C++/Java).
2. Iterates over a range starting from 0 up to 3 (exclusive). Like for loop in Python or like 'for(i=0; i<3; ++i)' in other programming languages (C/C++/Java).
3. Iterates over a range with a custom increment step for consecutive elements.
4. Iterates over a range in _reverse_ order.
3. Iterates over a range starting from 0 up to 3 (exclusive). This syntax equals to '0 until 3', which is better understood. (available in version 1.9.0)
4. Iterates over a range with a custom increment step for consecutive elements.
5. Iterates over a range in _reverse_ order.

Char ranges are also supported:

Expand Down