[英]js for in recursive function not working
My Code is in JS not working but in c is working. 我的代码在JS中不起作用但在c中正在工作。 Why?
为什么? Why For in calling recursive function not working?
为什么在调用递归函数时不起作用? What can i do for in recursive function?
在递归函数中我能做些什么? I must make this project with JavaScript.
我必须用JavaScript创建这个项目。
JS CODE JS代码
<a onClick="req(1)">Click</a>
<script>
function req(s){
if(s<5){
console.log(s);
for(i=0;i<s;i++){
req(s+1);
}
}
}
</script>
This code return this value : 1 2 3 4 此代码返回此值:1 2 3 4
C CODE C代码
#include <stdio.h>
void req(int s){
if(s<5){
printf("%d\n",s);
int i = 0;
for(i = 0;i<s;i++){
req(s+1);
}
}
}
void main(){
req(1);
}
It is : 它是 :
1 2 3 4 4 4 3 4 4 4 1 2 3 4 4 4 3 4 4 4
Always. 总是。 Declare.
宣布。 Your.
您的。 Variables.
变量。
Otherwise they become global in sloppy mode. 否则他们在草率模式下变得全球化。
function req(s) { if(s<10) { console.log(s); for(var i=0; i<s; i++) { req(s+1); } } } req(1);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.