Fibonacci sum

Report a typo

Below, there is a code that calculates Fibonacci numbers and their sum in the infinite cycle. Using the debugger, find the fibonacciSum value when the variable fibonacciCurrent becomes greater than 1000 for the first time and is added to the sum.

fun main() {
    var fibonacciPrevious = 1
    var fibonacciCurrent = 1
    var fibonacciSum = fibonacciPrevious + fibonacciCurrent

    while(true) {
        val tmp = fibonacciPrevious + fibonacciCurrent
        fibonacciPrevious = fibonacciCurrent
        fibonacciCurrent = tmp
        fibonacciSum += fibonacciCurrent
    }
}
Enter a number
___

Create a free account to access the full topic