infinite-loop

Switch statement within while loop in C

China☆狼群 提交于 2019-12-05 00:22:11
问题 There are several postings concerning switch statements within while loops, except for the fact that none of them are done in C, at least from what I've seen. C++ can create boolean expressions, which I'm aware of, but not in C. I have a while loop that contains a switch control. However, when I write break statements within my switch, it goes back to the beginning of the loop and makes my program run forever. Ignore the functions I use, for they work for sure. I just need some clarification

infinite loop in c++ [duplicate]

本小妞迷上赌 提交于 2019-12-05 00:04:15
问题 This question already has answers here : Infinite loop with cin when typing string while a number is expected (4 answers) Closed 9 months ago . I'm learning C++ and writing little programs as I go along. The following is one such program: // This program is intended to take any integer and convert to the // corresponding signed char. #include <iostream> int main() { signed char sch = 0; int n = 0; while(true){ std::cin >> n; sch = n; std::cout << n << " --> " << sch << std::endl; } } When I

Infinite loop invalidating the TimeManager

爱⌒轻易说出口 提交于 2019-12-04 23:39:59
I am experiencing a very tricky defect in my WPF application to track down. The error message is: An infinite loop appears to have resulted from repeatedly invalidating the TimeManager during the Layout/Render process. The stack trace (for what it's worth) is: at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget) at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget) at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) at MS.Internal.Threading

How can I add a user interrupt to an infinite loop?

核能气质少年 提交于 2019-12-04 21:14:34
问题 I have a ruby script below which infinitely prints numbers from 1 onward. How can I make the script stop its infinite execution through an interrupt in the terminal like 'Ctrl+C' or key 'q'? a = 0 while( a ) puts a a += 1 # the code should quit if an interrupt of a character is given end Through every iteration, no user input should be asked. 回答1: I think you will have to check the exit condition in a separate thread: # check for exit condition Thread.new do loop do exit if gets.chomp == 'q'

When sliding sprite, if sprite disappears off the side, it will wrap around to the opposite side?

a 夏天 提交于 2019-12-04 20:46:31
When sliding sprite, if sprite disappears off the side, i want to make it wrap around to the opposite side but I do not know how to do this while the sprite is simultaneously being pushed off one side i want the other bit that you can't see to appear on the opposite side like a loop some sort of wormhole thing. here is my code so far but it crashes and it only transports the sprite once the whole of the sprite disappears of the side. Loop also needs to run as an infinite loop until someone quits the app. for (int i =0; i<16; ++i) { MyNode *currentSprite = [c1array objectAtIndex:i]; if

Stopping an infinite loop in C++ when key is pressed [duplicate]

半世苍凉 提交于 2019-12-04 20:22:40
This question already has an answer here: How to detect key presses in a Linux C GUI program without prompting the user? 4 answers I have a program as given below: #include<iostream> using namespace std; int main() { while(true) { //do some task if(Any_key_pressed) break; } return 0; } how can exit from the loop if any key is pressed. C++ Compiler: GCC 4.2 and higher OS: Linux-Mint Thanks Standard C++ doesn't offer a way to do this. You will need a platform-specific API that tells you whether a key was pressed (or input is available on stdin, possibly) without blocking. Which means you need to

C++ Input a char instead of int lead to endless loop. How to check the wrong input?

荒凉一梦 提交于 2019-12-04 19:31:00
One part of my program: Let user input a series of integer, and then put them into an array. int n=0; cout<<"Input the number of data:"; cin>>n; cout<<"Input the series of data:"; int a[50]; for(i=0; i<n; i++) { cin>>a[i]; } Then, when user input wrong data such as a character 'a' or 'b'. The program will go into an infinite loop. How to catch the wrong cin? How to clear the buffer and give user the chance to input a right data again? Simply check if the input is a number first and then append it to the array int x; std::cin >> x; while(std::cin.fail()) { std::cin.clear(); std::cin.ignore(std:

Python - A keyboard command to stop infinite loop? [duplicate]

流过昼夜 提交于 2019-12-04 15:44:51
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: Why can't I handle a KeyboardInterrupt in python? I was playing around with some Python code and created an infinite loop: y = 0 x = -4 itersLeft = x while(itersLeft<0): y = y + x itersLeft = itersLeft - 1 print "y = ",y, "itersLeft = ", itersLeft print y Is there a keyboard shortcut that would allow me to stop the looping - allowing me to fix the loop and then restart it? I've tried Ctrl + C and didn't have any

strange string.IndexOf behavour

我是研究僧i 提交于 2019-12-04 13:47:39
问题 I wrote the following snippet to get rid of excessive spaces in slabs of text int index = text.IndexOf(" "); while (index > 0) { text = text.Replace(" ", " "); index = text.IndexOf(" "); } Generally this works fine, albeit rather primative and possibly inefficient. Problem When the text contains " - " for some bizzare reason the indexOf returns a match! The Replace function doesn't remove anything and then it is stuck in a endless loop. Any ideas what is going on with the string.IndexOf? 回答1:

Infinite loop using AndroidKeyStore authentication

我怕爱的太早我们不能终老 提交于 2019-12-04 12:53:37
My application enters an infinite loop when I use the AndroidKeyStore requiring user authentication to use the keys .setUserAuthenticationRequired(true); .setUserAuthenticationValidityDurationSeconds(60); It is assumed that an operation that uses a user's private key requires that the device has been unlocked, otherwise a UserNotAuthenticatedException is generated. The app must present the device authentication screen, and the next usage of the key will work. But, in my case always is thrown UserNotAuthenticatedException forcing app to show the unlock screen . It only happens in some devices.