Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 复杂重复函数_Javascript - Fatal编程技术网

Javascript 复杂重复函数

Javascript 复杂重复函数,javascript,Javascript,请帮我解决这个复杂的循环。我正在调用5个API URL,但是每个API URL都应该被调用一个特定的次数,然后它应该开始第二个、第三个、第四个和第五个URL,然后从上到下再次开始,并获得收益 https://www.example1.com should be called 4 times https://www.example2.com should be called 10 times https://www.example3.com should be called 8 times htt

请帮我解决这个复杂的循环。我正在调用5个API URL,但是每个API URL都应该被调用一个特定的次数,然后它应该开始第二个、第三个、第四个和第五个URL,然后从上到下再次开始,并获得收益

https://www.example1.com should be called 4 times
https://www.example2.com should be called 10 times
https://www.example3.com should be called 8 times
https://www.example4.com should be called 9 times
https://www.example5.com should be called 6 times
应该在上结束,然后再从上开始 不可阻挡的循环

我非常感谢并感谢所有回答这个问题的人

我的代码:


代码的结果在上述代码中注释。

使用变量作为每个函数的计数器,如下所示

var numberOfExecution=0;
function1(); // Start the procedure
function1()
{
 // do api call
 .......
 // after finishing your task, check if this function execution hits desired number
 numberOfExecution++;
 if(numberOfExecution==4)
{
 numberOfExecution=0;
 function2();
}
else
{
function1();
}
}
function2()
{
 // do api call
 .......
 // after finishing your task, check if this function execution hits desired number
 numberOfExecution++;
 if(numberOfExecution==6)
{
 numberOfExecution=0;
 function3();
}
else
{
function2();
}
}

在这些过程中,一个接一个的执行将继续达到所需的执行次数。

请不要截图。在这里复制并粘贴代码。为了更好地参考,我已经尝试了很多次粘贴代码,但是在堆栈溢出角色中没有成功,我只上传了一个图像。如果有人能告诉我如何分享我的代码,请告诉我know@sam将代码显示为文本请将代码、错误和数据添加为文本(),而不是图像。图片:A)不允许我们复制和粘贴代码/错误/数据进行测试;B) 不允许基于代码/错误/数据内容进行搜索;和。一般来说,文本格式的代码/错误/数据>>>>图像格式的代码/错误/数据>>无。除了代码格式的文本外,如果图像添加了一些仅由文本代码/错误/数据无法传达的重要信息,则只能使用图像。这是我的代码:您好,谢谢您的快速回复,我使用var counter=1;在函数内部,它可以工作,但我的代码不会再次启动。现在请看完整的过程,在达到所需的执行次数并切换到另一个api调用后,您需要重置计数器。非常感谢您的帮助!