while-loop

node.js: while loop callback not working as expected

孤街浪徒 提交于 2019-12-03 02:59:53
Knowing that while Node.js is working asynchronously, writing something like this: function sleep() { var stop = new Date().getTime(); while(new Date().getTime < stop + 15000) { ; } } sleep(); console.log("done"); ...would call the sleep(), block the server for the duration of the while loop (15secs) and just THEN print "done" to the console. As far as I understand, this is because Node.js is giving JavaScript only access to the main thread, and therefore this kidn of thing would halt further execution. So I understand the solution to this is to use callbacks: function sleep(callback) { var

input of while loop to come from output of `command`

安稳与你 提交于 2019-12-03 01:42:46
#I used to have this, but I don't want to write to the disk # pcap="somefile.pcap" tcpdump -n -r $pcap > all.txt while read line; do ARRAY[$c]="$line" c=$((c+1)) done < all.txt The following fails to work. # I would prefer something like... # pcap="somefile.pcap" while read line; do ARRAY[$c]="$line" c=$((c+1)) done < $( tcpdump -n -r "$pcap" ) Too few results on Google (doesn't understand what I want to find :( ). I'd like to keep it Bourne-compatible (/bin/sh), but it doesn't have to be. This is sh -compatible: tcpdump -n -r "$pcap" | while read line; do # something done However, sh does not

Optimize while and SQL in foreach

人走茶凉 提交于 2019-12-02 23:46:41
问题 My code : $text = '12-name-y-86'; $array = explode('-',$text); foreach($array as $value) { $sql = mysql_query("SELECT * FROM `table` WHERE `pid`='$value' ORDER BY `id` LIMIT 3"); echo '***'.$value.'***'; echo '<br />'; while($row = mysql_fetch_array($sql)) { echo $row['title']; echo '<br />'; } echo '<br /><br />'; } Print : 12 title1 title2 title3 name ti1 ti2 ti3 y tle1 tle2 tle3 86 mytitle1 mytitle2 mytitle3 This code work full buy for more values in $text , server has down ! 回答1: Try to

If/else proper indentation inside while loop [closed]

元气小坏坏 提交于 2019-12-02 23:45:08
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 3 years ago . I started learning programming with Python about a few weeks now and I am having some trouble. The following code is a tiny program that checks whether there's an even number in a list, if it finds the first even number, it breaks out of the loop: numbers = [1, 3, 5] position = 0 while position < len(numbers):

Help with PHP While function

元气小坏坏 提交于 2019-12-02 23:37:18
问题 Why is this not working? <?php $select = "select * from messages where user='$u'"; $query = mysqli_query($connect,$select) or die(mysqli_error($connect)); $row = mysqli_num_rows($query); $result = mysqli_fetch_assoc($query); $title = mysqli_real_escape_string($connect,trim($result['title'])); $message = mysqli_real_escape_string($connect,trim($result['message'])); while(($result = mysqli_fetch_assoc($query))){ echo $title; echo '<br/>'; echo '<br/>'; echo $message; } ?> where as this works -

PHP - While / Else error? [closed]

∥☆過路亽.° 提交于 2019-12-02 23:19:06
问题 This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 6 years ago . I have the following php code: <?php if (!isset($_REQUEST['search'])){ while(($write=mysql_fetch_array($gamesearched)) != null){ echo "Found!"; }else{

c++ for loop converted to a while loop

流过昼夜 提交于 2019-12-02 23:15:13
问题 Hi I wrote this code to print out factors of an integer with a for looop how do i write it with a while loop? for(int i = 1; i < integer+1; i++) { if(integer % i == 0) cout<< i<<" "; } 回答1: int i = 1; while (i < integer+1) { if(integer % i == 0) cout<< i<<" "; i++; } Or even better: int i = 0; while (++i < integer+1) { if(integer % i == 0) cout<< i<<" "; } 回答2: int i = 1; while(i < integer + 1) { // your current loop body goes here i++; } See equivalent forms of for loop. 回答3: Following code

NullPointerException in while loop when trying to add new Class instances to ArrayList

泄露秘密 提交于 2019-12-02 23:09:57
问题 The more I google this the more confused I'm getting. I'm bringing in a list of names of unknown length with some other details in from a CSV which I then need to turn into Person objects and store in a list called people which is the instance variable for the class Club, a list of its members basically. This is a very simplified version of something more complex I need to do in which I need to while loop through a file creating objects for each line which I then need to add to a list

Understanding the while loop in Tensorflow

怎甘沉沦 提交于 2019-12-02 22:32:15
I am using the Python API for Tensorflow . I am trying to implement the Rosenbrock function given below without the use of a Python loop: My current implementation is as follows: def rosenbrock(data_tensor): columns = tf.unstack(data_tensor) summation = 0 for i in range(1, len(columns) - 1): first_term = tf.square(tf.subtract(columns[i + 1], tf.square(columns[i]))) second_term = tf.square(tf.subtract(columns[i], 1.0)) summation += tf.add(tf.multiply(100.0, first_term), second_term) return summation I have tried implementing the summation in a tf.while_loop() ; however, I found the API somewhat

Simple C++ input from file…how to?

為{幸葍}努か 提交于 2019-12-02 21:31:22
I have a file: P 0.5 0.6 0.3 30 300 80 150 160 400 200 150 250 300 T r 45 0 0 s 0.5 1.5 0 0 t 200 –150 . . . When I read in 'P' I know that 3 floats will follow. That will be followed by a finite number of X and Y coordinates. The number will vary until a 'T' is reached which I have to recognize. Then there could be an 'r', 's' or 't' followed by some values. Anyways I know how to recognize 'P' and then take in the 2 floats but then I know I have to have a while loop for the X and Y coordinates which will stop when I get to a 'T'. I do not know enough about C++ to make the loop stop and