while-loop

Looping through editTexts to check values

和自甴很熟 提交于 2019-12-02 18:24:17
问题 I have one layout with 100 blank EditTexts, all named based on their row / column IDs (e.g. box0101, box0102 etc.). I then have another layout with 100 TextViews in exactly the same layout with one letter in each, named using the same convention (answerbox0101, answerbox0102 etc.) I want to write a loop that checks box0101 against answerbox0101, and so on until either one of the boxes does not match up, or it gets to 100 and all the boxes match. I am fine with writing the logic of the loop,

scanf loop, and signal handler

萝らか妹 提交于 2019-12-02 18:22:52
问题 Just learned about sigacation, also implemented another timer to make it more interesting. #include <stdio.h> #include <signal.h> #include <sys/time.h> volatile sig_atomic_t gotsignal; void handler(){ gotsignal = 1; } int main(){ struct sigaction sig; struct itimerval timer; timer.it_value.tv_sec = 5; timer.it_value.tv_usec = 0; timer.it_interval = timer.it_value; sig.sa_handler = handler; sig.sa_flags = 0; sigemptyset(&sig.sa_mask); setitimer(ITIMER_REAL, &timer, 0); sigaction(SIGALRM, &sig,

My first table valued function and cursor

醉酒当歌 提交于 2019-12-02 18:18:48
问题 I have this query: SELECT name, lastname FROM contestant WHERE name= 'John' AND lastname = 'Smith' I get several results from the query above and I need to use them for the following query: SELECT name, lastname,prize, city FROM draw WHERE name= name from table contestant AND lastname= name from table contestant Now I’m building a table valued function with a cursor and a WHILE so I can have a table with the results. Here’s my try, can you please help me complete it? it will be very helpful

Efficient and fast Python While loop while using sleep()

怎甘沉沦 提交于 2019-12-02 18:00:17
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 to effectively iterate over a while loop forever, while still maintaining a low consumption of CPU

how to iterate though delimited values in bash

♀尐吖头ヾ 提交于 2019-12-02 17:59:55
问题 BASH input: cat test 1 a;b;c;d 2 a;b;c;d 3 a;b;c;d desired output is: 1 a 1 b 1 c 1 d 2 a 2 b 2 c 2 d 3 a 3 b 3 c 3 d it could be something quite simple for programmers. thank you. 回答1: Solution 1st: Could you please try following. awk -F'[ ;]' '{for(i=2;i<=NF;i++){print $1,$i}}' Input_file Solution 2nd: Adding another awk too now. awk '{gsub(/;/,ORS $1 OFS)} 1' Input_file 回答2: This might work for you (GNU sed): sed -r 's/^((\s*\S+\s*)[^;]*);/\1\n\2/;P;D' file Replace each ; by a newline

Perl: while with no conditional

随声附和 提交于 2019-12-02 17:52:10
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? TLP $ 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 'while (<>) { }' while (defined($_ = <ARGV>)) { (); } -e syntax OK I would say that this is just the

While in a loop in Haskell

旧巷老猫 提交于 2019-12-02 17:33:39
问题 How to code the following pseudo-code in Haskell? x=0 for (i from 0 to 100): j=0 while ( f(i,j) >0 ): x+= f(i,j) j+=1 ( f some unimportant function.) I came up with something like this: a= [x| i<-[0..100], let s = takeWhile (\k-> (f i k > 0)) [0..], j<- s, let x = f i j ] Then Sum a does the work, but I need to compute f i j two times which is a little bit redundant. Can this be done with f computed only once or some better codes that run faster? 回答1: Here's a way that only computes f once

Python looping and program restart if true

久未见 提交于 2019-12-02 17:05:52
问题 Please help as I am a true beginner and would love to learn more. I am trying to learn more about looping so take a look at this code please. # lets the user input first number num1 = float(raw_input("Enter your first number ---> ")) # lets the user input second number num2 = float(raw_input("Enter your second number ---> ")) #the next four lines sets the basic mathematical equations addAns = num1+num2 subAns = num1-num2 mulAns = num1*num2 divAns = num1/num2 # ask the user to let the program

Testing while for multiple conditions (C language)

和自甴很熟 提交于 2019-12-02 16:55:50
问题 I have to create a menu wherein if the input is not valid. It should keep asking for a valid input. I've written it below (in C) #include <stdio.h> int main() { int input = 0; printf("What would you like to do? \n 1 (Subtraction) \n 2 (Comparison) \n 3 (Odd/Even) \n 4 (Exit) \n "); scanf_s("%d", &input); while (input != 1 || input != 2 || input != 3|| input != 4) { printf("Please enter a valid option \n"); scanf_s("%d", &input); } // At this point, I think it should keep testing variable

while loop to infinity when the input of a cin is a 'dot'

送分小仙女□ 提交于 2019-12-02 16:40:33
问题 I am having trouble using the cin method to acquire a variable. When the input is a number there is no problem, but when it is a special character like a dot [.], the whileloop loops into infinity. What am I doing wrong? cout << "What is your race" <<endl<<"1.Human\n2.troll\n3.zombie"<<endl; cin >> *race; while(*race<1||*race>3) { system("cls"); cout << "Wrong choice"<<endl<< "What is your race" <<endl<<"1.Human\n2.troll\n3.zombie"<<endl; cin >> *race; } I searched for the answer and i should