while-loop

Simple C++ input from file…how to?

邮差的信 提交于 2019-12-03 08:01:49
问题 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

Display text once within while loop on the first loop

守給你的承諾、 提交于 2019-12-03 07:58:19
问题 <?php $i = 0; while(conditionals...) { if($i == 0) print "<p>Show this once</p>"; print "<p>display everytime</p>"; $i++; } ?> Would this only show "Show this once" the first time and only that time, and show the "display everytime" as long as the while loop goes thru? 回答1: Yes, indeed. You can also combine the if and the increment, so you won't forget to increment: if (!$i++) echo "Show once."; 回答2: Rather than incrementing it every time the loop runs and wasting useless resource, what you

bash while loop threading

本小妞迷上赌 提交于 2019-12-03 06:54:19
i have a while loop reading lines from a $hosts while read line do ip=$line check done < $hosts my question is can I use some way to speed this up or run the check on 10 hosts at a time and each check is on a different IP and finish when all IP in $host have been checked? Thanks You can send tasks to the background by & If you intend to wait for all of them to finish you can use the wait command: process_to_background & echo Processing ... wait echo Done You can get the pid of the given task started in the background if you want to wait for one (or few) specific tasks. important_process_to

While loops using Await Async.

℡╲_俬逩灬. 提交于 2019-12-03 05:25:27
This Javascript function seems to use the while loop in an asynchronous way. Is it the correct way to use while loops with asynchronous conditions? var Boo; var Foo = await getBar(i) while(Foo) { Boo = await getBar3(i) if (Boo) { // something } Foo = await getBar(i) i++ } What I think it does is this: var Boo; var Foo; getBar(i).then( (a) => { Foo = a; if(Foo) { getBar3(i).then( (a) => { Boo = a if(Boo) { //something i++; getBar(i).then( (a} => { Repeat itself...} } } } }) If that's totally false could you show another way to do it with async await + while loop? Thanks!! Is it the correct way

Assigning value in while loop condition

孤者浪人 提交于 2019-12-03 05:11:57
问题 I found this piece of code on Wikipedia. #include <stdio.h> int main(void) { int c; while (c = getchar(), c != EOF && c != 'x') { switch (c) { case '\n': case '\r': printf ("Newline\n"); break; default: printf ("%c",c); } } return 0; } I'm curious about expression used as condition for while loop: while (c = getchar(), c != EOF && c != 'x') It's quite obvious what it does, but I've never seen this construction before. Is this specific to while loop? If not, how does parser/compiler determine

While Loops vs. For Loops in JavaScript? [closed]

半腔热情 提交于 2019-12-03 05:00:04
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 3 years ago . What are the benefits of using a while loop over a for loop? When I'm iterating through arrays, I always use a for loop so I wondered if I'm missing something here. I've never had a situation where a for loop doesn't do the job, but I'm worried that I may be picking up bad

Efficient and fast Python While loop while using sleep()

南笙酒味 提交于 2019-12-03 04:46:38
问题 I am attempting to communicate with a device over serial using Pyserial. As commands need to be continually sent, they have to be placed in a while loop in Python. I am currently using this code, and have taken a look at python process takes 100% CPU: while True: #do some serial sending here time.sleep(0.2) This code works. However, the sending speed is slow. I tried to make it faster by decreasing the sleep interval, but it seems to load the CPU a bit too much. In short, is there a any way

Perl: while with no conditional

时光总嘲笑我的痴心妄想 提交于 2019-12-03 04:43:30
问题 According to the doc, the while statement executes the block as long as the expression is true. I wonder why it becomes an infinite loop with an empty expression: while () { # infinite loop ... } Is it just inaccuracy in the doc? 回答1: $ perl -MO=Deparse -e 'while () { }' while (1) { (); } -e syntax OK It seems that while () {} and while (1) {} are equivalent. Also note that empty parens* are inserted in the empty block. Another example of pre-defined compiler behaviour: $ perl -MO=Deparse -e

For-loop vs while loop in R

自古美人都是妖i 提交于 2019-12-03 04:29:59
I have noticed a curious thing whilst working in R. When I have a simple program that computes squares from 1 to N implemented using for-loop and while-loop the behaviour is not the same. (I don't care about vectorisation in this case or apply functions). fn1 <- function (N) { for(i in 1:N) { y <- i*i } } AND fn2 <- function (N) { i=1 while(i <= N) { y <- i*i i <- i + 1 } } The results are: system.time(fn1(60000)) user system elapsed 2.500 0.012 2.493 There were 50 or more warnings (use warnings() to see the first 50) Warning messages: 1: In i * i : NAs produced by integer overflow . . .

Bash loop ping successful

白昼怎懂夜的黑 提交于 2019-12-03 03:49:22
问题 I'm thinking that this needs to be changed to a while clause, at the moment it'll wait till all 10000 pings are done, I need it to return when the ping is successful. The program "say" is on OSX it makes the computer speak. #!/bin/bash echo begin ping if ping -c 100000 8.8.8.8 | grep timeout; then echo `say timeout`; else echo `say the internet is back up`; fi OK I don't have rights to answer my own question so here's my answer for it after playing around: Thanks, yeah I didn't know about $?