while-loop

“while loop” not breaking (using Python)

孤者浪人 提交于 2019-12-11 06:28:40
问题 This is my code : #Choose Report def chooseReport(): print "Choose a report." while True: choice = raw_input("Enter A or B: ") if choice == 'a' or choice == 'A': reportA() break elif choice == 'b' or choice == 'B': reportB() break else: continue When I input either a or b , it just asks me to "Enter A or B" again. It doesn't go to the functions its supposed to. Any idea why is this? 回答1: The code is perfect, except a redundant else, as mentioned in the comment. Are you entering a (a + space)

assigning value from a vector (of shared pointer) to a shared pointer cause segmentation fault c++

≡放荡痞女 提交于 2019-12-11 06:19:05
问题 In my code, I have a vector <vector <vector <vector <std::tr1::shared_ptr<foo> > > > > named foosBoxes . The nested vector has a role of simulating a physical boxes position. I also have a while loop which cause a segmentation fault: vector<std::tr1::shared_ptr<foo> >::iterator fooit = foosBoxes[x][y][z].begin(); //x,y,z are valid integer std::tr1::shared_ptr<foo> aFoo; while (fooit != foosBoxes[x][y][z].end()){ aFoo = *fooit; //this cause segmentation fault fooit++; //some stuff which does

How to have two conditions in a While loop?

我是研究僧i 提交于 2019-12-11 06:18:29
问题 Basically I have two while loops in my code. All they do is count in increments of 1 from 0 to either 10 or -10. The vectors that count are "count1" and "count2". This is happening in my code in two separate while loops. However, I now need each count dependent on each other so I need them within the same loop. Is it possible to have the two separate while conditions working in one loop. For example, what I have now is: count1 = 0 count2 = 0 l_RWM = vector() r_RWM = vector() while (count1 <

How to convert Row by row execution in to SET based approach in SQL

天大地大妈咪最大 提交于 2019-12-11 06:15:32
问题 I'm working on a huge SQL code and unfortunately it has a CURSOR which handles another two nested CURSORS within it (totally three cursors inside a stored procedure), which handles millions of data to be DELETE,UPDATE and INSERT. This takes a whole lot of time because of row by row execution and I wish to modify this in to SET based approach From many articles it shows use of CURSORs is not recommend and the alternate is to use WHILE loops instead, So I tried and replaced the three CUROSRs

running two interdependent while loops in python?

不羁的心 提交于 2019-12-11 06:08:17
问题 For a web-scraping analysis I need two loops that run permanently, one returning a list with websites updated every x minutes, while the other one analyses the sites (old an new ones) every y seconds. This is the code construction that exemplifies, what I am trying to do, but it doesn't work: Code has been edited to incorporate answers and my research from multiprocessing import Process import time, random from threading import Lock from collections import deque class MyQueue(object): def _

Python returning values from infinite loop thread

风格不统一 提交于 2019-12-11 06:00:23
问题 So for my program I need to check a client on my local network, which has a Flask server running. This Flask server is returning a number that is able to change. Now to retrieve that value, I use the requests library and BeautifulSoup. I want to use the retrieved value in another part of my script (while continuously checking the other client). For this I thought I could use the threading module. The problem is, however, that the thread only returns it's values when it's done with the loop,

How to break an infinite loop

寵の児 提交于 2019-12-11 05:54:07
问题 this is my piece of code: // TODO Auto-generated method stub try { Socket clientSocket = new Socket("localhost", 8888); ObjectOutputStream ous = new ObjectOutputStream(clientSocket.getOutputStream()); while(sending) { Statistics statsData = setStatisticsData(); ous.writeObject(statsData); Thread.sleep(5000); } } catch(UnknownHostException uhe) { uhe.printStackTrace(); } catch(IOException ioe) { ioe.printStackTrace(); } catch (InterruptedException e) { // TODO Auto-generated catch block e

How do I append to a vector using a `while` loop?

我的未来我决定 提交于 2019-12-11 05:41:39
问题 I want to make a vector using a loop. Here's my R code: vec_teamCodes <- c() x <- 0 while (x < 10) { append(vec_teamCodes,"Hello") x <- x+1 } But when I run it, vec_teamCodes() remains NULL . Why? How do I fix my code? 回答1: Try this: vec_teamCodes <- c() x <- 0 while (x < 10) { vec_teamCodes <- c(vec_teamCodes,"Hello") # OR # vec_teamCodes <- append(vec_teamCodes,"Hello") x <- x+1 } [1] "Hello" "Hello" "Hello" "Hello" "Hello" "Hello" "Hello" "Hello" "Hello" "Hello" 来源: https://stackoverflow

Java, Finding smallest number in an array

為{幸葍}努か 提交于 2019-12-11 05:27:09
问题 Ths is a question from a past paper. I have been asked to create a static method arrayMin to find the smallest value in the array arr . I have to use a while loop and on each iteration, the variable min will return the smallest number from the first i elements. Is there a way to do this without calling another method/for loop and strictly using the while loop, as the question is only worth 4%(including writing loop invariants and javadoc). Not sure if I am overcomplicating the problem. public

Gradients error using TensorArray Tensorflow

天涯浪子 提交于 2019-12-11 04:53:56
问题 i am trying to implement multidimentional lstm in tensorflow, I am using TensorArray to remember previous states, i am using a complicated way to get two neigbours state(above and from left). tf.cond want that both posible condition to exist and to have the same number of inputs. this is why i added one more cell.zero_state to the (last index +1) of the states. then i using a function to get the correct indexes to the states. when i am trying to use an optimizer in order to minimize a cost, i