无尽的循环——不知道为什么
Endless loops - not sure why?
谁能告诉我为什么这个脚本会导致无限循环?
var words = ' ';
var spaces = /'s{9}/;
var p;
p = spaces.test(words);
do {
words = prompt("Test ", " ");
}
while (p != true);
var array = words.split(" ");
for(i = 0; i < array.length; i++) {
document.write(array[i] + "<br/>");
}
do {nothing with p} while(以p为条件)显然会永远运行下去。你是这个意思吗?
var words = ' ', spaces = /'s{9}/, p;
do {
p = spaces.test(words);
words = prompt("Test ", " ");
}
while (!p);
您不需要在每次循环时更改p。
对,我认为正则表达式不做你认为它做什么。's{9}将在一行中搜索9个空格。regex似乎是一个很难使用的工具,所以我做了我认为你想要使用分割,这似乎你已经熟悉了。
var words = ' ';
var p;
do {
words = prompt("Test", "");
p = words.split(" ");
}
while (p.length != 9);
var array = words.split(" ");
for(i = 0; i < array.length; i++) {
document.write(array[i] + "<br/>");
}
也许?
相关文章:
- 这个旋钮没有更新;我不知道为什么
- 我不知道为什么我的代码是错误的?又有什么错
- I'我不知道为什么我的代码没有'不起作用
- sqlite查询返回错误-can'我不知道为什么
- 我没有'我不知道为什么我的jqGrid子网格没有'不要给我看数据
- 我的代码很完美,但我现在不知道为什么我发现了问题
- 变量不起作用(不知道为什么)javascript
- 我可以'不要让这几行简单的代码正常工作,也不知道为什么
- 我的素数函数坏了,但我没有;我不知道为什么
- 当我从struts2操作在js函数中获得JSONArray时,它是空的,我不知道为什么
- 可以'我不知道为什么这个数字赢了;t增量
- 我不知道为什么ng repeat在我的代码中不起作用
- 标题下方的标签在再次单击时消失,JavaScript不知道为什么
- 历史.推送状态错误,我不知道为什么
- 只是不工作,不知道为什么
- 我的 innerHTML 命令没有改变任何东西,我不知道为什么
- JavaScript Validator 一直在说关于第 11 行的意外“如果”,我不知道为什么
- 我的地理位置(javascript)不起作用,我不知道为什么
- 我不知道为什么这个画布是空的
- 不知道为什么我的服务器超时.