while-loop

How to break this while(true) loop?

不羁岁月 提交于 2020-02-25 05:02:43
问题 Hi I am trying to break from this loop and return the coordinates when both if statements are true. However the loop is never ending. How can I fix it? public static String[] positionQuery(int dim, Scanner test_in) { Scanner scanner = new Scanner(System.in); System.out.println("Provide origin and destination coordinates."); System.out.println("Enter two positions between A1-H8:"); while(true) { String line = scanner.nextLine(); String[] coordinates = line.split(" "); if(coordinates.length ==

Multiplying two sets of numbers in python

最后都变了- 提交于 2020-02-07 04:41:51
问题 I have two lists of numbers, say [1, 2, 3, 4, 5] and [7, 8, 9, 10, 11] , and I would like to form a new list which consists of the products of each member in the first list with each member in the second list. In this case, there would be 5*5 = 25 elements in the new list. I have been unable to do this so far with a while() loop. This is what I have so far: x = 0 y = 99 results = [] while x < 5: x = x + 1 results.append(x*y) while y < 11: y = y + 1 results.append(x*y) 回答1: Wht dont you try

How to timeout a tail pipeline properly on shell

时光怂恿深爱的人放手 提交于 2020-02-06 08:48:13
问题 I am implementing monitor_log function which will tail the most recent line from running log and check required string with while loop, the timeout logic should be when the tail log running over 300 seconds, it must close the tail and while loop pipeline. The big issue i found is for some server the running log NOT keep generating, which means tail -n 1 -f "running.log" will also NOT generate output for while loop to consume, hence the timeout checking logic if [[ $(($SECONDS - start_timer))

How to timeout a tail pipeline properly on shell

佐手、 提交于 2020-02-06 08:44:21
问题 I am implementing monitor_log function which will tail the most recent line from running log and check required string with while loop, the timeout logic should be when the tail log running over 300 seconds, it must close the tail and while loop pipeline. The big issue i found is for some server the running log NOT keep generating, which means tail -n 1 -f "running.log" will also NOT generate output for while loop to consume, hence the timeout checking logic if [[ $(($SECONDS - start_timer))

How to timeout a tail pipeline properly on shell

偶尔善良 提交于 2020-02-06 08:44:16
问题 I am implementing monitor_log function which will tail the most recent line from running log and check required string with while loop, the timeout logic should be when the tail log running over 300 seconds, it must close the tail and while loop pipeline. The big issue i found is for some server the running log NOT keep generating, which means tail -n 1 -f "running.log" will also NOT generate output for while loop to consume, hence the timeout checking logic if [[ $(($SECONDS - start_timer))

Bash while loop with read and IFS

人走茶凉 提交于 2020-02-06 01:33:51
问题 I have to parse a file in the following format: line1_param1:line1_param2:line1_param3: line1_param2:line2_param2:line2_param3: line1_param3:line3_param2:line3_param3: And process it line by line, extracting all parameters from current line. Currently I've managed it in such a way: IFS=":" grep "nice" some_file | sort > tmp_file while read param1 param2 param3 do ..code here.. done < tmp_file unset IFS How can I avoid a creation of a temporary file? Unfortunately this doesn't work correctly:

Javascript continue statement in while loop causes an infinite loop

倾然丶 夕夏残阳落幕 提交于 2020-02-03 16:24:43
问题 I'm trying to create a while loop with a continue statement. However it seems to be causing an infinite loop and I can't figure out why. The code below to me seems like it should start with the var tasksToDo at 3 then decrement down to 0 skipping number 2 on the way. var tasksToDo = 3 while (tasksToDo > 0) { if (tasksToDo == 2) { continue; } console.log('there are ' + tasksToDo + ' tasks'); tasksToDo--; } 回答1: conitnue , will go back to the while loop. and tasksToDo will never get decremented

Javascript continue statement in while loop causes an infinite loop

ぐ巨炮叔叔 提交于 2020-02-03 16:24:08
问题 I'm trying to create a while loop with a continue statement. However it seems to be causing an infinite loop and I can't figure out why. The code below to me seems like it should start with the var tasksToDo at 3 then decrement down to 0 skipping number 2 on the way. var tasksToDo = 3 while (tasksToDo > 0) { if (tasksToDo == 2) { continue; } console.log('there are ' + tasksToDo + ' tasks'); tasksToDo--; } 回答1: conitnue , will go back to the while loop. and tasksToDo will never get decremented

How to have an async endless loop with Promises

China☆狼群 提交于 2020-02-03 05:16:06
问题 I need to have an "endless" while-loop which has promises inside it. Here's some example code: let noErrorsOccured = true while (noErrorsOccured){ someAsyncFunction().then(() => { doSomething(); }).catch((error) => { console.log("Error: " + error); noErrorsOccured = false; }); } function someAsyncFunction() { return new Promise ((resolve, reject) => { setTimeout(() => { const exampleBool = doSomeCheckup(); if (exampleBool){ resolve(); } else { reject("Checkup failed"); } }, 3000); }); } So

while($row = mysql_fetch_array($query)) doesn't work in second time

前提是你 提交于 2020-02-01 09:17:20
问题 I have: $query = mysql_query("SELECT ... "); while($row = mysql_fetch_array($query)) { first time used; } ... while($row = mysql_fetch_array($query)) { second time used; } In second time it doesn't work. Why? 回答1: That's because the internal data pointer has reached its end. To reread the query, either rewind the pointer with mysql_data_seek() , or reissue the query. 回答2: A MySQL result resource has an internal pointer, much like a PHP array, and when you have run through it once, the pointer