while-loop

c# loop until Console.ReadLine = 'y' or 'n'

别说谁变了你拦得住时间么 提交于 2019-12-02 09:41:54
I'm fairly new to c#, and writing a simple console app as practice. I want the application to ask a question, and only progress to the next piece of code when the user input equals 'y' or 'n'. Here's what I have so far. static void Main(string[] args) { string userInput; do { Console.WriteLine("Type something: "); userInput = Console.ReadLine(); } while (string.IsNullOrEmpty(userInput)); Console.WriteLine("You typed " + userInput); Console.ReadLine(); string wantCount; do { Console.WriteLine("Do you want me to count the characters present? Yes (y) or No (n): "); wantCount = Console.ReadLine();

python iterate though text file until condition is met

眉间皱痕 提交于 2019-12-02 09:34:01
i would like to continue iterating through the text file until the current condition inside the loop is met. here is the sample text: 10-01 N/A 10-02 N/A 10-03 N/A 10-04 N/A 10-05 N/A 10-06 N/A 10-07 N/A 10-08 N/A 10-09 N/A 10-10 N/A 10-11 N/A 10-12 N/A ===04===...... # Skip line until '01' is found ===12===...... # Skip line until '01' is found 05-01 N/A 05-02 N/A 05-03 N/A 05-04 N/A 05-05 N/A 05-06 N/A ===08===...... # Skip line until '07' is found ===11===...... # Skip line until '07' is found 05-07 N/A 05-08 N/A 05-09 N/A 05-10 N/A 05-11 N/A 05-12 N/A this is the while loop i am trying: x

Why doesn't my “While Loop” print the computation of finding the average “score”?

谁说我不能喝 提交于 2019-12-02 09:31:54
问题 I am writing a program that reads a sequence of positive integers input by the user. User will only enter one integer at a time.Then it will compute the average of those integers. The program will end when user enters 0. (0 is not counted in the average).The program will print out the average once the program ends. Question: My code stops working when I gets to the while loop hence it doesn't compute the input by user, hence prints out nothing. Why doesn't my while loop compute the average

Need to read white space and other chars C++

泪湿孤枕 提交于 2019-12-02 09:30:00
I have been working on this all day with no luck. Its night now and don't know what to do. My assignment is to read number of vowels, number of white spaces, and number of other characters in a user inputted sentence. I know i need to use cin.get(ch) for whitespaces, but don't know how. I also need to output the sentence to a file. Heres what I have so far: //Get data from user cout << "Enter your sentence on one line followed by a # to end it: " << endl; while (cin >> noskipws >> character && character != '#') { character = static_cast<char>(toupper(character)); if (character == 'A' ||

Having trouble with 'while' loop in javascript

和自甴很熟 提交于 2019-12-02 09:07:26
I'm new with javascript, and I'm having some trouble understanding why this code doesn't execute: var weight; wight=parseInt(prompt("Please, enter weight"); while(weight>0); { if (weight>199 && weight<300); { document.write("Tax will be" + weight*5); } else { document.write("Tax will be" + weight*10); } } Edit: I'm sorry, I mispelled some 'weights' while writing down the code here. Either way, that's not the problem. When I run this in google chrome, it just doesn't prompt. And when it prompted, it doesn't execute the 'if' statement. while (wight>0); The semicolon effectively makes that loop:

Update Text in While Loop Swift

两盒软妹~` 提交于 2019-12-02 09:03:47
My program has a while-loop that runs some code, generating various text statements as it goes along. The problem is that the UILabel only prints the last line of text in the series (my understanding is because it iterates too quickly). How do I get the label to print all of the text encountered, like one would see in console output? I looked at this link but the example doesn't seem to match my situation and not sure how to implement the fix (if that's even the right one): Update Label In While Loop Swift class ViewController: UIViewController { var locationArray = ["Place A", "Place B",

bash script stops execution in while loop - why?

拈花ヽ惹草 提交于 2019-12-02 09:01:40
问题 I have this bash script for converting .mp4 video to .mp3 audio. It runs, but does the loop only once, though there are more mp4 files in /home/myname/mp4dir. The script converts the first .mp4 file it finds to .mp3, unless there is already an .mp3 file. This should be done in a loop, but after the first call to ffmpeg the script stops. Why? #!/bin/bash find /home/myname/mp4dir -name "*.mp4" | while read f do fOut=`echo $f | sed s/mp4/mp3/` echo "convert $f => $fOut" if ! test -f $fOut then

Reading input using Scanner causes an infinite loop in Java [duplicate]

与世无争的帅哥 提交于 2019-12-02 08:45:59
This question already has an answer here: How to handle infinite loop caused by invalid input (InputMismatchException) using Scanner 5 answers In my program I'm trying to get a user to input an int between 1-3 and then do something based off what they type. If it is not a number or not one of the options then it will allow them to reenter a valid option. The issue I have is I'm having trouble brainstorming how to not have it infinitely loop and just allow them to enter in a number after the console tells them they entered an invalid input. int i = 0; while (i < 1) { try { int level = scan

Looping through editTexts to check values

落花浮王杯 提交于 2019-12-02 08:39:29
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, my issue is that i need the looping parameter to be part of the name of the EditText! How can I overcome

scanf loop, and signal handler

大憨熊 提交于 2019-12-02 08:37:51
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, NULL); int value, y = 100, x=0; while(!gotsignal && x < y){ printf("Insert a value: \n"); scanf("%d",