Tag: while loop

读取线路循环的shell脚本在第一行之后停止

我有以下的shell脚本。 目的是循环通过目标文件(其path是脚本的input参数)的每一行,并针对每一行进行工作。 现在,它似乎只能用于目标文件的第一行,并在处理该行后停止。 我的脚本有什么问题吗? #!/bin/bash # SCRIPT: do.sh # PURPOSE: loop thru the targets FILENAME=$1 count=0 echo "proceed with $FILENAME" while read LINE; do let count++ echo "$count $LINE" sh ./do_work.sh $LINE done < $FILENAME echo "\ntotal $count targets"

Bash:为什么pipe道input“读取”只有在喂入“while read …”构造时才起作用?

我一直在尝试从程序输出读取环境variables的input,如下所示: echo first second | read AB ; echo $A-$B 结果是: – A和B都是空的。 我读了关于在子shell中执行pipe道命令的bash,并且基本上阻止了pipe道input读取。 但是,以下内容: echo first second | while read AB ; do echo $A-$B ; done 似乎工作,结果是: first-second 有人能解释一下这里的逻辑吗? 是不是在while … done构造中的命令实际上是在与echo相同的shell中执行的,而不是在子shell中执行的?

打破了一阵子… Wend循环

我正在使用VBA的Wend循环。 Dim count as Integer While True count=count+1 If count = 10 Then ''What should be the statement to break the While…Wend loop? ''Break or Exit While not working EndIf Wend 我不想使用条件,如“虽然计数<= 10 … Wend

在SQL Server 2008中执行while循环

在SQL Server 2008中执行do while循环有没有什么方法?

PHP – while循环(!feof())不输出/显示所有内容

我正在尝试读取(和回显).txt文件的所有内容。 这是我的代码: $handle = @fopen("item_sets.txt", "r"); while (!feof($handle)) { $buffer = fgets($handle, 4096); $trimmed = trim($buffer); echo $trimmed; } 这是我的“item_sets.txt”: http ://pastebin.com/sxapZGuW 但是它不会回应所有的东西(并且会根据是否有多less个字符在它后面回显而改变显示的数量)。 var_dump()告诉我最后一个string永远不会打印出来。 看起来像这样: " string(45) ""[cu_well_tra 。但是如果我把一个 echo "whateverthisisjustarandomstringwithseveralcharacters"; , 我最后的输出行如下所示: " string(45) ""[cu_well_traveled_ak47]weapon_ak47" "1" " string(5) "} " 基本上我的代码是不打印/回应所有应该或至less不显示它。 提前致谢 :)

testing循环的顶部或底部? (while while do do while)

当我在大学攻读CS时(80年代中期),其中一个不断被重复的想法是总是写出循环testing在顶部(while …),而不是在底部(做… while)循环。 这些概念往往是支持与研究的参考,表明在顶部testing循环统计更有可能是正确的比底部testing的同行。 结果,我几乎总是写回路在顶部testing。 我不这样做,如果它在代码中引入额外的复杂性,但这种情况似乎很less。 我注意到一些程序员倾向于专门编写在底部testing的循环。 当我看到像这样的结构: if (condition) { do { … } while (same condition); } 或者反过来( if在内部的话),这让我怀疑他们是不是真的这样写了它,或者当他们意识到循环没有处理空情况时添加了if语句。 我做了一些Googlesearch,但一直没能find关于这个主题的任何文献。 你们(和加尔)如何写你的循环?

什么是NumberFormatException,如何解决?

Error Message: Exception in thread "main" java.lang.NumberFormatException: For input string: "Ace of Clubs" at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) at java.lang.Integer.parseInt(Integer.java:580) at java.lang.Integer.parseInt(Integer.java:615) at set07102.Cards.main(Cards.java:68) C:\Users\qasim\AppData\Local\NetBeans\Cache\8.1\executor-snippets\run.xml:53: Java returned: 1 BUILD FAILED (total time: 0 seconds) 我的while循环: while (response != 'q' && index < 52) { System.out.println(cards[index]); int first_value = Integer.parseInt(cards[index]); int value = 0; //Add a Scanner Scanner scanner […]