logo
  • 教程列表
  • SO官方文档
  • 科特林的循环
    • 循环遍历 iterables
    • 重复一次动作 x 次
    • 休息并继续
    • 迭代 kotlin 中的地图
    • 递归
    • 循环时
    • 用于迭代的功能构造
  1. StackOverflow 文档
  2. Kotlin 教程
  3. 科特林的循环
  4. 递归

递归

Created: November-22, 2018

与大多数编程语言一样,在 Kotlin 中也可以通过递归进行循环。

fun factorial(n: Long): Long = if (n == 0) 1 else n * factorial(n - 1)

println(factorial(10)) // 3628800

在上面的示例中,factorial 函数将自动重复调用,直到满足给定条件。

  • 循环时
  • 迭代 kotlin 中的地图

Copyright © 2018. All right reserved

tastones.com 备案号:鲁ICP备18045372号-1

  • 关于我们
  • 免责声明