Files
kotlin-fork/compiler/testData/codegen/box/controlStructures/factorialTest.kt
T
Ivan Kylchik c7435ba760 Replace all occurrences of WITH_RUNTIME with WITH_STDLIB
We are going to deprecate `WITH_RUNTIME` directive. The main reason
behind this change is that `WITH_STDLIB` directive better describes
its meaning, specifically it will add kotlin stdlib to test's classpath.
2021-11-17 15:26:38 +03:00

45 lines
862 B
Kotlin
Vendored

// WITH_STDLIB
import kotlin.test.assertEquals
fun facWhile(i: Int): Int {
var count = 1;
var result = 1;
while(count < i) {
count = count + 1;
result = result * count;
}
return result;
}
fun facBreak(i: Int): Int {
var count = 1;
var result = 1;
while(true) {
count = count + 1;
result = result * count;
if (count == i) break;
}
return result;
}
fun facDoWhile(i: Int): Int {
var count = 1;
var result = 1;
do {
count = count + 1;
result = result * count;
} while(count != i);
return result;
}
fun box(): String {
assertEquals(6, facWhile(3))
assertEquals(6, facBreak(3))
assertEquals(6, facDoWhile(3))
assertEquals(120, facWhile(5))
assertEquals(120, facBreak(5))
assertEquals(120, facDoWhile(5))
return "OK"
}