/**
 * You are an economist and you need to calculate the total amount of money a person will have after a certain number of years based on their initial principal, interest rate, and the number of years. However, you want to stop calculating the value if it exceeds a certain threshold. Complete the code to solve the exercise.
 *
 * @param principal the initial amount of money
 * @param rate the annual interest rate (in decimal form)
 * @param years the number of years
 * @return the total amount of money after the given number of years
 *
 * Note:
 * The break statement should be used to stop the calculation if the total amount exceeds $1,000,000.
 *
 * Example:
 * calculateInterests(10000.0, 0.05, 10) -> 16288.946267774418
 */
fun calculateInterests(principal: Double, rate: Double, years: Int): Double {

    var total = principal
    for (year in 0 until years) {
        total += total * rate
        if (total > 1_000_000) {
            break
        }
    }
    return total
}
/**
 * You are an economist and you need to calculate the total amount of money a person will have after a certain number of years based on their initial principal, interest rate, and the number of years. However, you want to stop calculating the value if it exceeds a certain threshold. Complete the code to solve the exercise.
 *
 * @param principal the initial amount of money
 * @param rate the annual interest rate (in decimal form)
 * @param years the number of years
 * @return the total amount of money after the given number of years
 *
 * Note:
 * The break statement should be used to stop the calculation if the total amount exceeds $1,000,000.
 *
 * Example:
 * calculateInterests(10000.0, 0.05, 10) -> 16288.946267774418
 */
fun calculateInterests(principal: Double, rate: Double, years: Int): Double {
/**
 * You are an economist and you need to calculate the total amount of money a person will have after a certain number of years based on their initial principal, interest rate, and the number of years. However, you want to stop calculating the value if it exceeds a certain threshold. Complete the code to solve the exercise.
 *
 * @param principal the initial amount of money
 * @param rate the annual interest rate (in decimal form)
 * @param years the number of years
 * @return the total amount of money after the given number of years
 *
 * Note:
 * The break statement should be used to stop the calculation if the total amount exceeds $1,000,000.
 *
 * Example:
 * calculateInterests(10000.0, 0.05, 10) -> 16288.946267774418
 */
fun calculateInterests(principal: Double, rate: Double, years: Int): Double {

    var total = principal
    for (year in 0 until years) {
        total += total * rate
        if (total > 1_000_000) {
            break
        }
    }
    return total
}