每20次做某事的通用代码(处理中)

问题描述 投票:-3回答:2

我想知道这样做的好方法是什么。我正在尝试实现我的处理代码,以便在if条件运行时每20次执行一次操作。因此,它将println(“ run”),例如5%的时间始终如一。

我在下面编写了伪代码,但想知道是否有更好的方法可以做到这一点。

create an array [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20] 
take a number out of a set and if the number is 1:
    println("run")
    get rid of the selected number within an array
if the set is empty, get a new set

我想知道这样做的好方法是什么。我正在尝试实现我的处理代码,以便在if条件运行时每20次执行一次操作。因此它将为...

algorithm pseudocode
2个回答
0
投票

您不需要数组。增加并重置的单个数字应足够:


0
投票

例如,您可以创建一个简单的forloop:

© www.soinside.com 2019 - 2024. All rights reserved.