while-loop

While loop condition in shell script

六月ゝ 毕业季﹏ 提交于 2019-12-24 07:25:50
问题 I have a text file called file.txt that has below entries :- healthy healthy healthy healthy healthy unhealthy initial healthy initial healthy Now i do a count of the number of healthy , initial and unhealthy in this file using below command :- grep -c healthy file.txt grep -c unhealthy file.txt grep -c initial file.txt Now i want a loop condition in shell script that does this for me :- while [ $(grep -c "healthy" file.txt) -lt 6 -a $(grep -c "unhealthy" file.txt) != 0 -a $(grep -c "initial"

How to break a while true with keyboard interruption?

心不动则不痛 提交于 2019-12-24 06:50:04
问题 How can I break a while True if I press a key?, and if it is possible, how can I break a while True if a press an x key (e.g. intro )?. while True: if something is pressed: print("STOP") break do_something() I tryied with inputs but you can't put: while True: i = input() or None if program wait > 3 seconds. # > = more than if != None: print("STOP") break do_something() Input stop all the while waiting for answer, and i don't want that. PD: I use win 10 64-bits, python 32-bits 3.6, terminal.

Why Scanf works wierd while taking a character

℡╲_俬逩灬. 提交于 2019-12-24 05:12:25
问题 Program Explantion:- I have written a program which takes character input from the user infinite no. of times and print the entered input.Here is the program #include<stdio.h> int main() { int i=1; char a; while (i!=0) { printf("Enter %d th value\n",i); scanf("%c",&a); printf("Entered input is %c\n",a); i++; } } Output of the above program:- Enter 1 th value q Entered input is q Enter 2 th value Entered input is Enter 3 th value r Entered input is r Enter 4 th value Entered input is Enter 5

Why Scanf works wierd while taking a character

半城伤御伤魂 提交于 2019-12-24 05:12:12
问题 Program Explantion:- I have written a program which takes character input from the user infinite no. of times and print the entered input.Here is the program #include<stdio.h> int main() { int i=1; char a; while (i!=0) { printf("Enter %d th value\n",i); scanf("%c",&a); printf("Entered input is %c\n",a); i++; } } Output of the above program:- Enter 1 th value q Entered input is q Enter 2 th value Entered input is Enter 3 th value r Entered input is r Enter 4 th value Entered input is Enter 5

Combination Generator in JAVA

有些话、适合烂在心里 提交于 2019-12-24 03:44:01
问题 I am trying to find all combinations of items in several arrays. The number of arrays is random (this can be 2, 3, 4, 5...). The number of elements in each array is random too. e.g., I have the 3 arrays : String[][] array1 = {{"A1","A2","A3"},{"B1","B2","B3"},{"C1","C2"}}; I would like to generate an array with all possible combinations : A1, B1, C1 A1, B1, C2 A1, B2, C1 A1, B2, C2 A1, B3, C1 A1, B3, C2 A2, B1, C1 A2, B1, C2 ... 回答1: You could create the combinations by using a "counter-like"

jQuery while loop not waiting for animation

让人想犯罪 __ 提交于 2019-12-24 03:25:47
问题 I have a jQuery function that does a .clone() on an object, and then an .insertAfter() and a .slideDown() on the cloned object. This whole function is wrapped inside a while loop. I will keep this as short and concise as possible and show a generic example: while (statement) { // code for clone and insert ... $("#newly_created_object").slideDown(500); } How can I prevent the next while-loop from firing before the .slideDown() animation (or any other kind of animation for that matter) ends ?

counting the number of sentences in a paragraph in c

不打扰是莪最后的温柔 提交于 2019-12-24 03:22:26
问题 As part of my course, I have to learn C using Turbo C (unfortunately). Our teacher asked us to make a piece of code that counts the number of characters, words and sentences in a paragraph (only using printf, getch() and a while loop.. he doesn't want us to use any other commands yet). Here is the code I wrote: #include <stdio.h> #include <conio.h> void main(void) { clrscr(); int count = 0; int words = 0; int sentences = 0; char ch; while ((ch = getch()) != '\n') { printf("%c", ch); while (

Multiple select queries using while loop in a single table? Is it Possible?

筅森魡賤 提交于 2019-12-24 02:52:10
问题 I have 2 tables. Table A has Date, ISBN (for Book), Demand(demand for that date). Table B has Date, ISBN (for Book), and SalesRank. The sample data is as follows: The DailyBookFile has 150k records for each date, from year 2010 (i.e. 150k * 365 days * 8 years) rows. Same goes with SalesRank Table having about 500k records for each date DailyBookFile Date Isbn13 CurrentModifiedDemandTotal 20180122 9780955153075 13 20180122 9780805863567 9 20180122 9781138779396 1 20180122 9780029001516 9

How do I stop while loop from running infinitely?

江枫思渺然 提交于 2019-12-24 02:43:24
问题 Can't figure out how to stop this while loop from repeating infinitely. I'm using hasNextInt to check if user input is an int. If an int is not entered the loop repeats infinitely. public static void validatingInput(){ Scanner scan = new Scanner(System.in); boolean valid = false; int userNumber = 0; while(!valid) { System.out.println("Enter number between 1 and 20: "); if (scan.hasNextInt()) { userNumber = scan.nextInt(); valid = true; } else System.out.print("Not an int. "); } } 回答1: You

HandBrakeCLI command break while loop?

独自空忆成欢 提交于 2019-12-24 02:12:06
问题 In a bash script, result of find is /path/to/file1.nrg /path/to/file2.nrg /path/to/file3.nrg i have this while loop: process preset processpreset () { x=$1 # Replace , by -o -iname for file types. iname=" -o -iname \*." # Find specified files. Eval allow var prst1_in with find. eval "find "$fpath" -type f \( -iname \*."${prst_in[x]//,/$iname}" \) -size ${prst_lim_size[x]}" | sort | while read -r i do titles=$(HandBrakeCLI --input "$i" --scan |& grep -Po '(?<=DVD has )([0-9]+)') if (( $titles