Skip to content

Commit 7ff924a

Browse files
authored
[KTLN-796] Add Samples (#838)
1 parent 945985a commit 7ff924a

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.baeldung.assignwhile
2+
3+
fun simpleVarAssignmentOutsideLoop() {
4+
val sentinelValue = 10
5+
var value: Int = 0
6+
while (value != sentinelValue) {
7+
// do something...
8+
value++
9+
}
10+
}
11+
12+
fun whileWithBreakStatement() {
13+
val sentinelValue = 10
14+
while (true) {
15+
val value = getValue()
16+
if (value == sentinelValue) break
17+
// Process value
18+
}
19+
}
20+
21+
fun usingDoWhile() {
22+
val sentinelValue = 10
23+
do {
24+
val value = getValue()
25+
if (value == sentinelValue) break
26+
// Process value
27+
} while (true)
28+
}
29+
30+
private fun getValue() = 10

0 commit comments

Comments
 (0)