do-while

How to exit loop with ENTER

吃可爱长大的小学妹 提交于 2019-12-24 14:04:00
问题 How do I exit this loop when user presses ENTER. This is part of the codes I have done. I am having problems in how to code when user presses ENTER. static String[] itemList = new String[10]; do { System.out.print("Enter item (press ENTER to exit) " + (count + 1) + ": "); String item = input.next(); itemList[count] = item; if (item == "") count = itemList.length; 回答1: You are comparing String s using == not .equals() . This compares the pointer to the String , not the contents of the String .

do while syntax for java

别说谁变了你拦得住时间么 提交于 2019-12-24 00:25:11
问题 Ages since I have written a do while. Whats wrong with this do while int i = 0; do { System.out.println(i); } while(++i == 500); I only goes once through the loop, and IMO it should iterate 500 times. 回答1: You probably meant while (++i < 500); instead of while (++i == 500); 回答2: It is a do-while loop of Java, not the repeat-until loop of Pascal. Its expression specifies the continuation condition , not the exit condition . do { System.out.println(i); } while(++i != 500); 回答3: It will only

do while loops can't have two cin statements?

自古美人都是妖i 提交于 2019-12-23 22:32:58
问题 I'm just following a simple c++ tutorial on do/while loops and i seem to have copied exactly what was written in the tutorial but i'm not yielding the same results. This is my code: int main() { int c=0; int i=0; int str; do { cout << "Enter a num: \n"; cin >> i; c = c + i; cout << "Do you wan't to enter another num? y/n: \n"; cin >> str; } while (c < 15); cout << "The sum of the numbers are: " << c << endl; system("pause"); return (0); } Right now, after 1 iteration, the loop just runs

Nodejs - Re-Calling function on error callback - Is there a non blocking way?

大憨熊 提交于 2019-12-21 18:03:22
问题 I got a function which makes a request to an API. Sometimes the API got some hiccups and isnt available for a second or two every now and then, resulting in an error on which I'd like to call the function again. Since there are another 70~80 lines of code following this callback, I wouldnt like to split the flow with an if(error) <do the same stuff> else <as here> After trying for quite some time I ended up using a do-while(error) loop, which works but blocks. Is there an async way of doing

Discord.js message after receiving emoji reaction

瘦欲@ 提交于 2019-12-21 05:42:08
问题 It it possible to make a Discord bot send a message once a previous message has received a reaction? I was thinking about something like: if(cmd === `${prefix}list`) { var i = 0; let embed = new Discord.RichEmbed() .addField("List", "Content"); let anotherembed = new Discord.RichEmbed() .addField("Message", "List has been completed!"); return message.channel.send(embed); do { message.channel.send(anotherembed + 1); } while (i !== 0) && (reaction.emoji.name === "✅"); } 回答1: That's not

Is there a way to perform a do-while?

混江龙づ霸主 提交于 2019-12-21 03:26:10
问题 I'm planning to use a do-while loop in MATLAB. Is there a way to do that? 回答1: while(true) %code if condition==false break; end end 回答2: Here's another option in MATLAB (more close to a do-while syntax): do = true; while(do || condition) % things to do... do = false; end 回答3: At least, Octave has do-until . This example creates a variable fib that contains the first ten elements of the Fibonacci sequence. fib = ones (1, 10); i = 2; do i++; fib (i) = fib (i-1) + fib (i-2); until (i == 10) Of

Java do-while loop isn't working

这一生的挚爱 提交于 2019-12-20 05:57:25
问题 I want my program to keep asking the question until it gets a response it can use, specifically a number from 0 to 20. I have a lot of other stuff on this class, so here is a small excerpt where the do-while is (I have named the variables and all that for everything). public static void main(String[] args) { do { halp = 1; System.out.println("What level is your fort?"); Scanner sc = new Scanner(System.in); try { fortLevel = Integer.parseInt(sc.nextLine()); } catch(NumberFormatException e)

syntax error near unexpected token `<'

…衆ロ難τιáo~ 提交于 2019-12-19 04:17:06
问题 StudentAnwser=() inputScriptFile=001.sh while IFS= read -r line; do StudentAnwser+=( "$line" ) done < <( sh $inputScriptFile test.txt ) it returns a error foo.sh: line 22: syntax error near unexpected token `<' foo.sh: line 22: ` done < <( sh $inputScriptFile test.txt )' what's wrong with that? I follow the solution from other question for reading line from result 回答1: You get the error because process substitution (the <(some command) part) is not a standard feature (defined in POSIX) in sh

do-while is the fastest loop in php?

僤鯓⒐⒋嵵緔 提交于 2019-12-18 13:34:00
问题 I have profiled for , while and do-while loops with something simple: while ($var < 1000000) { ++$var; } do { ++$var; } while ($var < 1000000); for ($var = 0; $var < 1000000; ++$var) { //do nothing } by comparing microtime() before and after the loops. The do-while loop is by a considerable amount the fastest loop. do-while is actually faster than while by almost half. I know that they are for different purposes ( while checks the condition before the loop executes and do-while executes at

WHILE LOOP with IF STATEMENT MYSQL

让人想犯罪 __ 提交于 2019-12-18 12:19:14
问题 I would like to create a stored routine for MySQL that figures out the number of business or working days for a month (Working Days are Monday thru Friday). It's a syntax error however I don't know what the syntax error is. All it tells me is: 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHILE(@daycount < @totaldays) DO IF (WEEKDAY(@checkweekday) < 6) THEN ' at line 2 My Syntax Error is in the