while-loop

The output -1 becomes a slash in the loop

拥有回忆 提交于 2020-07-31 06:48:27
问题 Surprisingly, the following code outputs: / -1 The code: public class LoopOutPut { public static void main(String[] args) { LoopOutPut loopOutPut = new LoopOutPut(); for (int i = 0; i < 30000; i++) { loopOutPut.test(); } } public void test() { int i = 8; while ((i -= 3) > 0) ; String value = i + ""; if (!value.equals("-1")) { System.out.println(value); System.out.println(i); } } } I tried many times to determine how many times this would occur, but, unfortunately, it was ultimately uncertain,

Bash if condition to check variable for changes over time

喜你入骨 提交于 2020-07-30 04:12:08
问题 Wondering if it's possible to finagle this logic (checking a variable for changes over time and running a loop while true) into a bash if statement or while loop condition. I was hoping for something like: var=$(du -h *flat*.vmdk) var2=$(sleep 1 ; du -h *flat*.vmdk) if [[ $var != $var2 ]]; then while true do echo -ne $(du -h *flat*.vmdk)\\r sleep 1 done else echo "Transfer complete" fi I've also played with a while loop , rather than an if then with no luck. while [ $var != $var2 ] ; do echo

Bash if condition to check variable for changes over time

一世执手 提交于 2020-07-30 04:10:07
问题 Wondering if it's possible to finagle this logic (checking a variable for changes over time and running a loop while true) into a bash if statement or while loop condition. I was hoping for something like: var=$(du -h *flat*.vmdk) var2=$(sleep 1 ; du -h *flat*.vmdk) if [[ $var != $var2 ]]; then while true do echo -ne $(du -h *flat*.vmdk)\\r sleep 1 done else echo "Transfer complete" fi I've also played with a while loop , rather than an if then with no luck. while [ $var != $var2 ] ; do echo

Declaring String Variables within a while loop without it looping all throughout - java

假如想象 提交于 2020-07-16 06:57:37
问题 I am stuck at a part where I am supposed to declare a string variable called "phrase", where it shouldn't loop, all the way through. to give you an idea my task is: Similar to Option 1 except the user enters 'N' (instead of 'Q') when they are done entering results for the first team. Then, the program inputs a second team name and its results until 'Q' is entered. Outputs two statements, like the statements in option 1 followed by a third statement that says which team is in first place

Java comparing string to regex - while loop

人盡茶涼 提交于 2020-07-16 02:48:13
问题 I want the user to enter a string and if the string does not match my regex expression then I want a message to be outputted and the user to enter a value again. The problem is even when the string matches the regex it is treating it as if it does not match. My regex: This should equal - Name, Name [[A-Z][a-zA-Z]*,\s[A-Z][a-zA-Z]*] My while loop: System.out.println("Enter the student's name in the following format - surname, forename: "); studentName = input.next(); while (!studentName.equals

Java comparing string to regex - while loop

心已入冬 提交于 2020-07-16 02:46:10
问题 I want the user to enter a string and if the string does not match my regex expression then I want a message to be outputted and the user to enter a value again. The problem is even when the string matches the regex it is treating it as if it does not match. My regex: This should equal - Name, Name [[A-Z][a-zA-Z]*,\s[A-Z][a-zA-Z]*] My while loop: System.out.println("Enter the student's name in the following format - surname, forename: "); studentName = input.next(); while (!studentName.equals

Trying to repeat until condition is false

懵懂的女人 提交于 2020-07-09 05:32:09
问题 I am trying to make a loop that repeats until the user input correct information (no whitespaces or blank). This is what I have so far but it only repeats one time. I want it to repeat until user fills in a correct name, e.g. Oskar/OSKAR/oskar System.out.print("Name: "); String name = scanner.nextLine(); name = name == null ? "" : name.trim(); while(name.isEmpty()) { System.out.println("Wrong data"); System.out.print("Name: "); String name1 = scanner.nextLine(); name = name1; } 回答1: You need

Python - How to break while loop after empty value in a int turning input? [duplicate]

≡放荡痞女 提交于 2020-07-04 03:22:31
问题 This question already has answers here : Asking the user for input until they give a valid response (20 answers) Closed 3 years ago . I want to make the while loop break when empty input is typed. I know that the error is due to the int function because it cant turn to integer an empty input but how can i do what i'm trying to write? while True: numb = int(input("number")) if numb % 2 == 0: print("this number is even") elif numb % 2 != 0: print("this number is odd") elif numb == '': break 回答1

Python - How to break while loop after empty value in a int turning input? [duplicate]

大城市里の小女人 提交于 2020-07-04 03:21:13
问题 This question already has answers here : Asking the user for input until they give a valid response (20 answers) Closed 3 years ago . I want to make the while loop break when empty input is typed. I know that the error is due to the int function because it cant turn to integer an empty input but how can i do what i'm trying to write? while True: numb = int(input("number")) if numb % 2 == 0: print("this number is even") elif numb % 2 != 0: print("this number is odd") elif numb == '': break 回答1