break

How can I exit a while(1) based on a user input?

寵の児 提交于 2019-12-11 01:46:50
问题 I have a simple server-client terminals. The server receives strings from the client and processes it. The server will only start processing once it receives the end_of_input character which in my case is '&' . The while loop below is meant to allow a user to input a number of different strings and should stop performing as it receives '&' . while(1) { printf("Enter string to process: "); scanf("%s", client_string); string_size=strlen(client_string); //I want to escape here if client_string

Using javascript how to break the while loop after a set time? [duplicate]

守給你的承諾、 提交于 2019-12-11 00:08:53
问题 This question already has answers here : Leave a loop after 2 seonds (3 answers) Closed last year . I have a while loop which looks like this: while(s1 != "#EANF#") { iimPlay("CODE:REFRESH"); iimPlay("CODE:TAG POS=1 TYPE=* ATTR=TXT:Contacted:* EXTRACT=TXT") var s1 = iimGetLastExtract(); } it will refresh the web page until it finds what it wants. However sometimes it becomes an infinite loop and I want to simply set a timer so that it would break the while loop and carry on. I tried looking

Rewriting JavaScript break-to-label in Ruby

别说谁变了你拦得住时间么 提交于 2019-12-10 16:07:32
问题 I'm porting a JavaScript library to Ruby, and have come across the following insanity (heavily abbreviated): function foo(){ if (foo) ... loop: while(go()){ if (...) break; switch(...){ case a: break loop; case b: case c: if (...) break loop; ... break; case d: if (...) break loop; // fall through case e: if (...) break loop; ... break; case f: if (...) break loop; object_init: do{ switch(...){ case a: ... break; case b: ... break object_init; } } while(...); ... break; } } } (You can view

Why does this break statement break not work?

一曲冷凌霜 提交于 2019-12-10 13:58:57
问题 I have the following code: public void post(String message) { final String mess = message; (new Thread() { public void run() { while (true) { try { if (status.equals("serviceResolved")) { output.println(mess); Game.log.fine("The following message was successfully sent: " + mess); break; } else { try {Thread.sleep(1000);} catch (InterruptedException ie) {} } } catch (NullPointerException e) { try {Thread.sleep(1000);} catch (InterruptedException ie) {} } } } }).start(); } In my log file I find

Using try-finally block inside while loop [duplicate]

ぐ巨炮叔叔 提交于 2019-12-10 13:47:58
问题 This question already has answers here : Does a finally block always get executed in Java? (47 answers) Closed last year . I am trying to understand the mechanism when i use finally inside a while loop. In the below code. In finally line prints and than the while breaks. I was expecting the code not to reach the finally block. Or if it reaches the finally block, there is no break there so the while should continue.. Can anyone explain how this works ? while(true){ System.out.println("in while

How to break a while loop from an if condition inside the while loop?

╄→гoц情女王★ 提交于 2019-12-10 12:30:48
问题 I want to break a while loop of the format below which has an if statement. If that if statement is true, the while loop also must break. Any help would be appreciated. while(something.hasnext()) { do something... if(contains something to process){ do something break if condition and while loop } } 回答1: The break keyword does exactly that. Here is a contrived example: public static void main(String[] args) { int i = 0; while (i++ < 10) { if (i == 5) break; } System.out.println(i); //prints 5

AutoHotKey keystroke break loop

ぐ巨炮叔叔 提交于 2019-12-10 04:21:33
问题 Using AutoHotKey, I have a rather simple loop script that I want to be able to break by the stroke of a key. I tried a few different codes from websites but it doesn't seem to work. Here's the code: #g:: Loop 20 { MouseClick, left, 142, 542 Sleep, 1000 MouseClick, left, 138, 567 Sleep, 1500 MouseClick, left, 97, 538 Sleep, 1000 } 回答1: Use a global variable (keepCycling) and toggle it to break the loop. Global variables should be declared in the beginning of a script. 回答2: Adding a global

How to break out of a nested parallel (OpenMP) Fortran loop idiomatically?

冷暖自知 提交于 2019-12-10 04:01:46
问题 Here's sequential code: do i = 1, n do j = i+1, n if ("some_condition(i,j)") then result = "here's result" return end if end do end do Is there a cleaner way to execute iterations of the outer loop concurrently other than: !$OMP PARALLEL private(i,j) !$OMP DO do i = 1, n !$OMP FLUSH(found) if (found) goto 10 do j = i+1, n if ("some_condition(i,j)") then !$OMP CRITICAL !$OMP FLUSH(found) if (.not.found) then found = .true. result = "here's result" end if !$OMP FLUSH(found) !$OMP END CRITICAL

PHP - Break after return?

坚强是说给别人听的谎言 提交于 2019-12-10 01:06:43
问题 do I need to use break here or will it stop looping and just return once? for($i = 0; $i < 5; $i ++) { if($var[$i] === '') return false; // break; } Thank you! 回答1: It will run just once, stop looping, and exit from the function/method. It could be argued though that this is bad style. It is very easy to overlook that return later, which is bad for debugging and maintenance. Using break might be cleaner: for($i = 0; $i < 5; $i ++) { if($var[$i] === '') { set_some_condition; break; } } if

C# switch/break

假如想象 提交于 2019-12-09 15:07:04
问题 It appears I need to use a break in each case block in my switch statement using C#. I can see the reason for this in other languages where you can fall through to the next case statement. Is it possible for case blocks to fall through to other case blocks? Thanks very much, really appreciated! 回答1: Yes, you can fall through to the next case block in two ways. You can use empty cases, which don't need a break, or you can use goto to jump to the next (or any) case: switch (n) { case 1: case 2: