while-loop

Shell script while read line loop stops after the first line

回眸只為那壹抹淺笑 提交于 2020-01-11 09:43:29
问题 I have the following shell script. The purpose is to loop thru each line of the target file (whose path is the input parameter to the script) and do work against each line. Now, it seems only work with the very first line in the target file and stops after that line got processed. Is there anything wrong with my script? #!/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

Why is While (rs.next()) statement ending after 1st iteration?

久未见 提交于 2020-01-11 09:03:29
问题 I am using a SELECT statement to get data from a table and then insert it into another table. However the line "stmt.executeQuery(query);" is inserting the first line from the table then exits. When I comment this line out, the while loop loops through all the lines printing them out. The stacktrace isn't showing any errors. Why is this happening? try{ String query = "SELECT * FROM "+schema_name+"."+table; rs = stmt.executeQuery(query); while (rs.next()) { String bundle = rs.getString("BUNDLE

How to fetch 2 times in MYSQL PDO without FETCHALL

醉酒当歌 提交于 2020-01-10 05:06:26
问题 I have this sample query: $STH = $DBH->query("SELECT id FROM table"); I want to get the first row and then loop and display all rows. So I use the following to get the first row: $STH->setFetchMode(PDO::FETCH_ASSOC); $first_row = $STH->fetch(); $first_row = $first_row['id']; I use while loop to display all rows again: while ($list = $STH->fetch()) { $id = $list['id']; echo $id; } Now the while skips the first row and I want it to be displayed. Is there an equivalent to mysql_data_seek to

Converting for loops to while loops in python

元气小坏坏 提交于 2020-01-09 11:23:09
问题 I am struggling to find an efficient way to convert these for loops to a working set of while loops. Any Suggestions? I am using 2.7 def printTTriangle(height): for row in range(1,height+1): # print row T's for col in range(1,row+1): print 'T', print Thank you all for your help! 回答1: It's like this: def printTTriangle(height): row = 1 while row < height+1: col = 1 while col < row+1: print 'T', col += 1 print row += 1 Here's how I did it. For example, let's convert this line: for row in range

Create a pause inside a while loop in javascript

扶醉桌前 提交于 2020-01-09 07:12:30
问题 I would like to create a pause inside a while loop so that I can create n animations that each appear 3 seconds after the other. I've tried the following, but it doesn't work. Would love to have someone show me what I'm doing wrong. Thanks!! i=0; while (i < n) { someanimation(); setTimeout(function(){ i++; }, 3000); }; 回答1: setTimeout does not pause; it asks Javascript to run some other code later. Googling for "setTimeout loop" tells you exactly what you need to know. If you look around a

What is an off-by-one error and how do I fix it?

佐手、 提交于 2020-01-09 05:05:21
问题 What is an off-by-one error? If I have one, how do I fix it? 回答1: An off-by-one error is for example when you write intend to perform a loop n times and write something like: for (int i = 1; i < n; ++i) { ... } or: for (int i = 0; i <= n; ++i) { ... } In the first case the loop will be executed (n - 1) times and in the second case (n + 1) times, giving the name off-by-one. Other variations are possible but in general the loop is executed one too many or one too few times due to an error in

“GUI while loop”

僤鯓⒐⒋嵵緔 提交于 2020-01-07 09:21:29
问题 Okay, I have a code that looks like this: public class Test { private JPanel dummy; public checker() { dummy = new JPanel(); dummy.setVisible(false); dummy.addComponentListener(new ComponentAdapter() { @Override public void componentShown(ComponentEvent arg0) { dummy.setVisible(false); runCheck(); } }); runCheck(); } private void runCheck() { if (a) { //do something dummy.setVisible(true); } } } This will create a dummy JPanel and add a component adapter that will fire each time dummy is set

While statment with multiple values contained in an array

旧街凉风 提交于 2020-01-07 08:09:07
问题 I have a database that holds several bits of info per entry. I use a while statement to loop through each one and display what I call "plots" which will be a number, each entry can hold multiple plots EG 111, 222, 333 what I need to do I have the while statement (or another method that may suit better) to check whether that plot numbers that each entry holds are contained within a array that I set and then display so information EG: while ($row = mysqli_fetch_array($aa, MYSQLI_ASSOC)) {

Waiting for an process to quit in PowerShell

前提是你 提交于 2020-01-07 07:47:10
问题 Is there a possibility to wait for an process to quit, without it needs to running? I know there is the keyword WaitForExit, but to use this the process needs to run. My second question is, if there is a possibility to use an else-Statement in an while loop. Tried it already, but it always said that there isnt an function called else. 回答1: Do Until Do { Sleep 5 } Until (Get-Process iexplore); Will wait until iexplore is found While While (Get-Process iexplore) { Sleep 5 } Will wait until

Waiting for an process to quit in PowerShell

大憨熊 提交于 2020-01-07 07:47:09
问题 Is there a possibility to wait for an process to quit, without it needs to running? I know there is the keyword WaitForExit, but to use this the process needs to run. My second question is, if there is a possibility to use an else-Statement in an while loop. Tried it already, but it always said that there isnt an function called else. 回答1: Do Until Do { Sleep 5 } Until (Get-Process iexplore); Will wait until iexplore is found While While (Get-Process iexplore) { Sleep 5 } Will wait until