我是靠谱客的博主 温柔裙子,最近开发中收集的这篇文章主要介绍为scheme添加for循环语句,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

有三个辅助关键字in, from和to
能够 break和continue
语法有三种
(for n in '(1 2 3 4 5 6 7 8 9 10)
(if (> n 8) (break #f))
(if (even? n) (continue #f))
(display n)
(display " "))
=> 1 3 5 7 #f
(for n from 1 to 100
(if (> n 10) (break #f))
(display n)
(display " "))
=> 1 2 3 4 5 6 7 8 9 10 #f
(for n from 100 99 to 1
(if (< n 90) (break #f))
(display n)
(display " "))
=> 100 99 98 97 96 95 94 93 92 91 90 #f

(define (product nums)
  (define p 1)
  (for n in nums
    (when (zero? n)
      (set! p 0)
      (break #f))
    (set! p (* p n)))
  p)

(product '(1 2 3 0 2)) ;=> 0                                                                                                                          
(product

最后

以上就是温柔裙子为你收集整理的为scheme添加for循环语句的全部内容,希望文章能够帮你解决为scheme添加for循环语句所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(52)

评论列表共有 0 条评论

立即
投稿
返回
顶部