Skip to content

Commit

Permalink
Iterators / Loops in Koltin
Browse files Browse the repository at this point in the history
  • Loading branch information
smartherd committed Sep 16, 2018
1 parent e53074b commit 5bfed24
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/12_for_loop.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@


/*
* FOR Loop
* */
fun main(args: Array<String>) {

for (i in 1..10) {

if (i % 2 == 0) {
println(i)
}
}

println()

for (i in 10 downTo 0) {

if (i % 2 == 0) {
println(i)
}
}
}

26 changes: 26 additions & 0 deletions src/13_while_loop.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@


/*
* WHILE Loop
* */
fun main(args: Array<String>) {

var i = 0
while (i <= 10) {
if (i % 2 == 0) {
println(i)
}
i++
}

println()

var j = 10
while (j >= 0) {
if (j % 2 == 0) {
println(j)
}
j--
}
}

27 changes: 27 additions & 0 deletions src/14_do_while.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@


/*
* DO WHILE Loop
* */
fun main(args: Array<String>) {

var i = 0

do {
if (i % 2 == 0) {
println(i)
}
i++
} while (i <= 10)

println()

var j = 10

do {
if (j % 2 == 0) {
println(j)
}
j--
} while (j >= 0)
}
25 changes: 25 additions & 0 deletions src/15_break_keyword.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@


/*
* BREAK Keyword and Labelled FOR Loop
* */
fun main(args: Array<String>) {

for (i in 0..4) {
println(i)

if (i == 2) {
break
}
}

println()

myLoop@ for (i in 1..3) {
for (j in 1..3) {
println("$i $j")
if (i == 2 && j == 2)
break@myLoop
}
}
}
23 changes: 23 additions & 0 deletions src/16_continue_keyword.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@


/*
* CONTINUE Keyword and Labelled FOR Loop
* */
fun main(args: Array<String>) {

for (i in 1..3) {
if (i == 2)
continue
println(i)
}


myLoop@ for (i in 1..3) {
for (j in 1..3) {
if (i == 2 && j == 2) {
continue@myLoop
}
println("$i $j")
}
}
}

0 comments on commit 5bfed24

Please sign in to comment.