好像
while( condition ) {
//do stuff
}
Run Code Online (Sandbox Code Playgroud)
完全等同于
for( ; condition; ) {
//do stuff
}
Run Code Online (Sandbox Code Playgroud)
有没有理由使用后者而不是前者?
我正在重构一个非常大的方法,里面有很多重复.
在该方法中有许多while循环,包括:
if ( count > maxResults){
// Send error response
sendResponse(XMLHelper.buildErrorXMLString("Too many results found, Please refine your search"), out, session);
break;
Run Code Online (Sandbox Code Playgroud)
我想把它作为一种方法提取,因为它在当前的这个方法中发生了3次,但是当我这样做时,我在中断时得到一个错误,因为它不再在循环中.问题是仍然需要打破while循环,但仅在达到最大结果数时.
有什么建议?
正如标题所说,我不明白为什么f^:proposition^:_ y是一个while循环.我实际上已经使用了几次,但我不明白它是如何工作的.我得到了^:重复函数,但我对它在该语句中的双重用法感到困惑.
我也无法理解为什么f^:proposition^:a: y有效.这与前一个迭代相同,但返回所有迭代中的值,而不是上一个迭代中的最后一个值.
a:是一个空盒子,我得到的具有特殊含义,^:但即使在查看字典后,我无法理解它.
谢谢.
我将差异结果保存到文件中:
bash-3.00$ cat /tmp/voo
18633a18634
> sashabrokerSTP
18634a18636
> sashatraderSTP
21545a21548
> yheemustr
Run Code Online (Sandbox Code Playgroud)
我真的需要登录:
bash-3.00$ cat /tmp/voo | egrep ">|<"
> sashaSTP
> sasha
> yhee
bash-3.00$
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试迭代下摆并打印名称时,我会收到错误.我只是不明白使用"if"和"while循环"的基本原理.最终,我想使用while循环,因为我想对行做一些事情 - 显然一次while只加载一行到内存中,而不是一次整个文件.
bash-3.00$ while read line; do if [[ $line =~ "<" ]] ; then echo $line ; fi ; done < /tmp/voo
bash-3.00$
bash-3.00$
bash-3.00$ while read line; do if [[ egrep "<" $line ]] ; then echo $line ; fi ; done < /tmp/voo
bash: conditional …Run Code Online (Sandbox Code Playgroud) 我正在看一个用经典ASP编写的网页,我正处于'while'语句的中间.我想使用Chrome开发者工具调试页面上的值.我试过插入
console.log(value);
Run Code Online (Sandbox Code Playgroud)
它适用于C#应用程序,但它Expected end of statement在console.log我插入的行中抛出了一个.
我只是在寻找关于如何使用经典asp调试器的快速提示?
我是C语言编程的新手.我需要这个程序遍历文件夹中的所有文件并为每个文件打印这些属性.此时它正在打印文件夹的属性.
#include <sys/types.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <dirent.h>
int main(int argc, char *argv[])
{
DIR *dp;
struct stat file_stats;
if (argc != 2) {
fprintf(stderr, "Usage: fstat FILE...\n");
return EXIT_FAILURE;
}
if ((stat(argv[1], &file_stats)) == -1) {
perror("fstat");
return EXIT_FAILURE;
}
dp = opendir("./");
if (dp == NULL) {
perror("couldn't open directory");
return EXIT_FAILURE;
}
while (readdir(dp)) {
printf("filename: %s\n", argv[1]);
printf(" device: %lld\n",
file_stats.st_dev);
printf(" protection: %o\n",
file_stats.st_mode);
printf(" number of hard links: %d\n", …Run Code Online (Sandbox Code Playgroud) 运行此代码,我希望它将测试变量增加5秒然后完成.
import java.util.Timer;
import java.util.TimerTask;
public class Test {
private static boolean running;
public static void main( String[] args ) {
long time = 5 * 1000; // converts time to milliseconds
long test = Long.MIN_VALUE;
running = true;
// Uses an anonymous class to set the running variable to false
Timer timer = new Timer();
timer.schedule( new TimerTask() {
@Override
public void run() { running = false; }
}, time );
while( running ) {
test++;
}
timer.cancel();
System.out.println( …Run Code Online (Sandbox Code Playgroud) 到目前为止,我所拥有的是
import random
def go():
rounds = 0
while rounds < 5:
number = random.randint(1, 5)
if number == 1:
print('a')
elif number == 2:
print('b')
elif number == 3:
print('c')
elif number == 4:
print('d')
elif number == 5:
print('e')
rounds = rounds + 1
go()
Run Code Online (Sandbox Code Playgroud)
并且输出结束了生物的某些东西
e
e
c
b
e
Run Code Online (Sandbox Code Playgroud)
如何制作一个数字只使用一次,字母不重复?(例如某事)
a
e
b
c
d
Run Code Online (Sandbox Code Playgroud)
提前致谢
我一直在阅读其他帖子,但无法理解.无论我在重复结束时输入什么,它总是重复循环.我试过while(repeat != "Quit" or repeat != "quit" or repeat != "b" or repeat != "B" or repeat != "no" or repeat != "No"):但它仍然没有奏效.我不知道还有什么可以尝试的.这个while循环有什么问题?
repeat = "d"
print "Please answer questions using the choices (A, B, C, etc.)"
time.sleep(2.1738)
while repeat != "Quit" or repeat != "quit" or repeat != "b" or repeat != "B" or repeat != "no" or repeat != "No":
print "A) Round Edges"
print "B) Straight Edges"
Edges1 = raw_input("Does the shape have round edges …Run Code Online (Sandbox Code Playgroud) 我在退出以下循环时遇到问题.这是一个简单的程序,hello如果随机值大于5则打印.程序运行良好一次但是当我尝试再次运行它时会进入无限循环.
from random import *
seed()
a = randint(0,10)
b = randint(0,10)
c = randint(0,10)
count = 0
while True:
if a > 5 :
print ("aHello")
count = count + 1
else :
a = randint(0,10)
if b > 5 :
print ("bHello")
count = count + 1
else :
b = randint(0,10)
if c > 5 :
print ("cHello")
count = count + 1
else :
c = randint(0,10)
if count == 20 :
count = …Run Code Online (Sandbox Code Playgroud) while-loop ×10
loops ×3
python ×3
java ×2
asp-classic ×1
bash ×1
break ×1
c ×1
c++ ×1
console.log ×1
debugging ×1
for-loop ×1
if-statement ×1
j ×1
linux ×1
methods ×1
posix ×1
python-3.x ×1
random ×1
timer ×1
timertask ×1