Skip to content

Commit

Permalink
[ADD/#1] 코틀린 반복문 실습 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
b1urrrr committed Nov 29, 2023
1 parent 202744f commit 83f62bd
Showing 1 changed file with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import kotlin.random.Random
const val num = 20 // Compile Time Constant

fun main() {
practiceLoop()
}

private fun practicePrint() {
Expand All @@ -23,7 +24,7 @@ private fun practiceVariablesAndConstants() {
i = 20

val num = 20
// num = 30
// num = 30 (X)
}

private fun practiceTypeConversion() {
Expand Down Expand Up @@ -99,3 +100,28 @@ private fun practiceConditionalExpression() {
val booleanResult = if (i > 10) true else false
println(booleanResult)
}

private fun practiceLoop() {
val items = listOf(1, 2, 3, 4, 5)

for (item in items) {
print(item)
}

items.forEach { item ->
print(item)
}

// for (int i = 0; i < items.length; i++)
for (i in 0..(items.size - 1)) {
print(items[i])
}

for (i in 0 until items.size) {
print(items[i])
add *

break
continue
}
}

0 comments on commit 83f62bd

Please sign in to comment.