while-loop

Inner While Loop only run once

走远了吗. 提交于 2019-12-12 03:14:49
问题 The purpose of the code is to find a portion of a string (from one document) in a long list of strings (another document), and return the results to a list. I have two while loops, one nested in the other. The outer loop reads each line of that document, and the inner reads each loop of its document. For some reason, the inner while only runs once (for the outer loop's first iteration). Can you explain why and how I could fix it? It seems like it only reads all the lines once and then doesn't

python sleep for memory consumption measurement not accurate

谁说我不能喝 提交于 2019-12-12 03:08:15
问题 i have a python script ( runner.py ) which regularly measures memory consumption of a process. to monitor memory consumption I use a helper class called ProcessTimer.py . processtimer is implemented based on the solution given here. the solution is based on polling. so there is a while -loop. in this while -loop memory consumption is measured and then the thread sleeps for a certain amount of time to ensure regular measurements. in my case sleep is done for 500ms. however, my problem is that

How do I reset a while loop?

天大地大妈咪最大 提交于 2019-12-12 03:05:20
问题 Here is an extract for some code that I am working on. Just wondering how would I go about resetting the nested loop? It remains at the end of the file when the first loop runs again. while(fscanf(fp2,"%s", wordcheck)!=EOF)//Reads word from text file into array// { for (i=0; wordcheck[i]; i++) { wordcheck[i] = tolower(wordcheck[i]);//makes all characters lower case// } printf("%s", wordcheck); while(fscanf(fp1,"%s", worddict)) { if(strcmp(wordcheck, worddict)==0)//compare strings// { printf(

Why is this code snippet infinitely looping?

前提是你 提交于 2019-12-12 02:53:45
问题 I'm fairly new to programming, and I'm trying to filter inputs from cin (for no particular reason; It is the only input method I know of right now) such that one can only enter 1-10 and get the "positive" response. Here is my code: #pragma region Check cin is a valid input (an integer between 1 and 10, not a string or number out of range) int input; bool valid2=false; while (!valid2) { cout << "Enter an integer (1-10): "; cin >> input; if (!cin || input > 10 || input < 1) { cout << "Error:

reader.Read() only read once even when there are multiple rows to read

試著忘記壹切 提交于 2019-12-12 02:53:11
问题 I have the code while (reader.Read()) { if (reader[incrementer]!=DBNull.Value){ string playerToInform = reader.GetString(incrementer).ToString(); string informClientMessage = "ULG=" + clientIP + ","; //User Left Game byte[] informClientsMessage = new byte[informClientMessage.Length]; informClientsMessage = Encoding.ASCII.GetBytes(informClientMessage); playerEndPoint = new IPEndPoint(IPAddress.Parse(playerToInform), 8001); clientSocket.SendTo(informClientsMessage, playerEndPoint); }

C#: access variable in the inner scope from the outer scope

大憨熊 提交于 2019-12-12 02:52:28
问题 I'm creating an instance of a class inside a while loop - I need the while loop to get the input arguments i need to create the instance (I have to read it in from an extern file). But then I would like to have access to the instance from outside the loop. Is there a possibility? public static <class> leseProjektDatei() { while ((zeile = datei.ReadLine()) != null) { Debug.WriteLine(zeile); string id, wetterdatei, fruchtfolge, bodenprofil, grundwasser; id = zeile.Substring(0, 5); wetterdatei =

While Looping an Array

天大地大妈咪最大 提交于 2019-12-12 02:51:02
问题 I'm trying to understand a book from Don Gosselin on ASP.NET Programming with Visual C#. To solve it I just simply make it to work by adhering to while loops: one while loop is to assign a number to an array element, the other while loop is to display that array. Total array count displays 1 through 100. This should have worked but didn't. Visual Studio 2013 debugger for some reason assigns count = 100, that's why it's failing. <% int count = 0; int[] numbers = new int[100]; while (count <=

imacros javascript return top

泪湿孤枕 提交于 2019-12-12 02:48:37
问题 I'm writing a imacros script using javascript and I've a problem. var result = ""; var Loop = 1; while(true) { iimSet("Loop",Loop); var macro; macro="CODE:"; macro +="SET !DATASOURCE site.csv" + "\n"; macro +="SET !DATASOURCE_LINE {{Loop}}" + "\n"; macro +="URL GOTO=https://www.google.com/search?q={{!COL1}}" + "\n"; macro +="WAIT SECONDS=1" + "\n"; iimPlay(macro); var ret_code = iimPlay("CODE:TAG POS=1 TYPE=DIV ATTR=ID:resultStats"); if(ret_code<0){break;} ret_code = iimPlay("CODE:TAG POS=1

Logical Error in Shell script.Please help (UNIX)

安稳与你 提交于 2019-12-12 02:43:09
问题 Following is a source code which takes in only 'files',lists the file permissions of a file and prints the output by replacing r=READ,w-WRITE,x-EXECUTABLE. It should also echo " User ".But the My problem here is that I have replaced ' - ' by User but then if the file has a permission of r--x,it also prints "User" @ that point.I know its not a correct way to go about it.Can anyone suggest me a better way of echoing "User". I have also tried printing it before the loop but then it won't serve

boolean flag not read in while loop (java)

让人想犯罪 __ 提交于 2019-12-12 02:26:41
问题 I've written a program to bounce a ball around a screen. The program as written below does not work (the ball just moves off screen). However if I declare the boolean variables atHorizontalEdge and atVerticalEdge inside the while loop, it seems to work. Why is that the case? As the booleans are defined for the entire run() method, shouldn't it be callable by the while loop even though its outside the while loop? import acm.program.*; import acm.graphics.*; import java.awt.*; public class