Search Results

Search found 8557 results on 343 pages for 'infinite loop'.

Page 34/343 | < Previous Page | 30 31 32 33 34 35 36 37 38 39 40 41  | Next Page >

  • C++: Case statement within while loop?

    - by Jason
    I just started C++ but have some prior knowledge to other languages (vb awhile back unfortunately), but have an odd predicament. I disliked using so many IF statements and wanted to use switch/cases as it seemed cleaner, and I wanted to get in the practice.. But.. Lets say I have the following scenario (theorietical code): while(1) { //Loop can be conditional or 1, I use it alot, for example in my game char something; std::cout << "Enter something\n -->"; std::cin >> something; //Switch to read "something" switch(something) { case 'a': cout << "You entered A, which is correct"; break; case 'b': cout << "..."; break; } } And that's my problem. Lets say I wanted to exit the WHILE loop, It'd require two break statements? This obviously looks wrong: case 'a': cout << "You entered A, which is correct"; break; break; So can I only do an IF statement on the 'a' to use break;? Am I missing something really simple? This would solve a lot of my problems that I have right now.

    Read the article

  • C++: Switch statement within while loop?

    - by Jason
    I just started C++ but have some prior knowledge to other languages (vb awhile back unfortunately), but have an odd predicament. I disliked using so many IF statements and wanted to use switch/cases as it seemed cleaner, and I wanted to get in the practice.. But.. Lets say I have the following scenario (theorietical code): while(1) { //Loop can be conditional or 1, I use it alot, for example in my game char something; std::cout << "Enter something\n -->"; std::cin >> something; //Switch to read "something" switch(something) { case 'a': cout << "You entered A, which is correct"; break; case 'b': cout << "..."; break; } } And that's my problem. Lets say I wanted to exit the WHILE loop, It'd require two break statements? This obviously looks wrong: case 'a': cout << "You entered A, which is correct"; break; break; So can I only do an IF statement on the 'a' to use break;? Am I missing something really simple? This would solve a lot of my problems that I have right now.

    Read the article

  • multiple mysql_real_query() in while loop

    - by Steve
    It seems that when I have one mysql_real_query() function in a continuous while loop, the query will get executed OK. However, if multiple mysql_real_query() are inside the while loop, one right after the other. Depending on the query, sometimes neither the first query nor second query will execute properly. This seems like a threading issue to me. I'm wondering if the mysql c api has a way of dealing with this? Does anyone know how to deal with this? mysql_free_result() doesn't work since I am not even storing the results. //keep polling as long as stop character '-' is not read while(szRxChar != '-') { // Check if a read is outstanding if (HasOverlappedIoCompleted(&ovRead)) { // Issue a serial port read if (!ReadFile(hSerial,&szRxChar,1, &dwBytesRead,&ovRead)) { DWORD dwErr = GetLastError(); if (dwErr!=ERROR_IO_PENDING) return dwErr; } } // Wait 5 seconds for serial input if (!(HasOverlappedIoCompleted(&ovRead))) { WaitForSingleObject(hReadEvent,RESET_TIME); } // Check if serial input has arrived if (GetOverlappedResult(hSerial,&ovRead, &dwBytesRead,FALSE)) { // Wait for the write GetOverlappedResult(hSerial,&ovWrite, &dwBytesWritten,TRUE); //load tagBuffer with byte stream tagBuffer[i] = szRxChar; i++; tagBuffer[i] = 0; //char arrays are \0 terminated //run query with tagBuffer if( strlen(tagBuffer)==PACKET_LENGTH ) { sprintf(query,"insert into scan (rfidnum) values ('"); strcat(query, tagBuffer); strcat(query, "')"); mysql_real_query(&mysql,query,(unsigned int)strlen(query)); i=0; } mysql_real_query(&mysql,"insert into scan (rfidnum) values ('2nd query')",(unsigned int)strlen("insert into scan (rfid) values ('2nd query')")); mysql_free_result(res); } }

    Read the article

  • Best way to make sure I get all available options array/loop

    - by jaz872
    OK, here is my problem. I'm looking for the best way to loop through a bunch of options to make sure that I hit all available options. Some detail. I've created a feature that allows a client to build images that are basically other images layered on top of each other. These other images are split up into different groups. They have links on the side of the image that they can click to scroll through all the different images to view them. I'm now making an automated process that is going to run the function that changes the image when a user clicks one of the links. I need to make sure that every possible combo of the different images is hit during this process. So I have an array with the number of options for each group. The current array is [3, 9, 3, 3] My question is what is the best way to loop through this to make sure that all possible options will be shown? I apologize if this seems simple for someone out there, but I'm just having trouble wrapping my head around it. Hopefully if that person is out there, they can give a helping hand :)

    Read the article

  • bubble sort logic error

    - by Arianule
    I was trying a basic sorting exercise and I was hoping I could receive some help with what is probably a basic logic error. int[] numbers = new int[] { 2, 5, 11, 38, 24, 6, 9, 0, 83, 7 }; for (int loop = 0; loop < numbers.Length; loop++) { Console.WriteLine(numbers[loop]); } Console.WriteLine("Performing a bubble sort"); bool flag = false; do { for (int loop = 0; loop < numbers.Length - 1; loop++) { if (numbers[loop] > numbers[loop + 1]) { int temporary = numbers[loop]; numbers[loop] = numbers[loop + 1]; numbers[loop + 1] = temporary; flag = true; } } } while (flag == false); for (int loop = 0; loop < numbers.Length; loop++) { Console.WriteLine(numbers[loop]); } kind regards arianule

    Read the article

  • How to get jquery to append output immediately after each ajax call in a loop

    - by david_nash
    I'd like to append to an element and have it update immediately. console.log() shows the data as expected but append() does nothing until the for loop has finished and then writes it all at once. index.html: ... <body> <p>Page loaded.</p> <p>Data:</p> <div id="Data"></div> </body> test.js: $(document).ready(function() { for( var i=0; i<5; i++ ) { $.ajax({ async: false, url: 'server.php', success: function(r) { console.log(r); //this works $('#Data').append(r); //this happens all at once } }); } }); server.php: <?php sleep(1); echo time()."<br />"; ?> The page doesn't even render until after the for loop is complete. Shouldn't it at least render the HTML first before running the javascript?

    Read the article

  • All articles with infinite scroll, or one per page for usability and SEO?

    - by Rana Prathap
    Imagine a hypothetical website with all user generated content of single page articles. Here are some ways to structuring such a website: Putting up more than one article in one page and creating an infinite scroll or a pager. The fact that the articles may not be on the same topic makes this a less search engine friendly way. Giving a unique page to each article and putting up a list of links/titles in the front page with or without a teaser and a thumbnail. This might make the home page look unprofessional. Keeping the front page clean, without direct links to internal pages. Which method would be a search engine friendly and user friendly way to do this?

    Read the article

  • Indicator-cpufreq does not work at 12.04 ¿infinite loop insaid?

    - by Juan
    Good night, i want to use indicator-cpufreq, but it is not possible, i think that when i start it, i get an infinite loop and it doesnt start I think i am doing it well, here you have a snapshoot when i try to start it http://i.stack.imgur.com/mvaYf.jpg But 6 or 7 minutes later, it continues at the same point, i have to stop it with Ctrl-c, and shows that: http://i.stack.imgur.com/Vi0pp.jpg It says:" Traceback (most recent call last): File "/usr/bin/indicator-cpufreq", line 82, in gtk.main() KeyboardInterrupt" I do not have idea of what do for fix that, i hope you can help me to do that Thanks for your time and sorry about my english

    Read the article

  • While Loop Taking Alot of CPU Usage

    - by CuriousUser
    I am creating a keystroke logger for my personal interest, as well wanting to know how to capture and use them as functions (like key shortcuts). I got the code to learn how keylogger and GetAsyncKeyState() work: http://www.rohitab.com/discuss/index.php?showtopic=9931 I got it to run under Code::Blocks, but the weirdest things is that when I check my task manager, my CPU Usage rises to 100%. When I close the program, it goes back down, and goes back up to 100 when I turn it back on. I presume it's because of the infinite while loop, constantly checking for inputs, but I wanna know if there's anyway to decrease the CPU usage, without losing function. P.S How would I make a key shortcut? Like press (Ctrl + E) to make the program exit?

    Read the article

  • Debugging a Browser Redirect Loop

    - by just_wes
    Hi all, I am using CakePHP with the Auth and ACL components. My page loads fine for non-registered users, but if I try to log in as a registered user I get an infinite redirect loop in the browser. I am sure that this is some sort of permissions problem, but the problem exists even for users who have permissions for everything. The only way to prevent this behavior is to allow '*' in my AppController's beforeFilter method. What is the best way to debug this sort of problem? Thanks!

    Read the article

  • Multithreaded Win32 GUI message loop

    - by Dave18
    When do you need to use this type of modified message loop in multithreaded application? DWORD nWaitCount; HANDLE hWaitArray[4]; BOOL quit; int exitCode; while (!quit) { MSG msg; int rc; rc = MsgWaitForMultipleObjects(nWaitCount, hWaitArray, FALSE, INFINITE,QS_ALLINPUT); if (rc == WAIT_OBJECT_O + nWaitCount) { while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { if (msg.message == WM_QUIT) { quit = TRUE; exitCode = msg.wParam; break; } TranslateMessage(&msg); DispatchMessage(&msg); } } else if (rc >= WAIT_OBJECT_0 && rc < WAIT_OBJECT_0 + nwaitCount) { int nlndex = rc - WAIT_OBJECT_0; } else if (rc >= WAIT_ABANDONED_0 && rc < WAIT_ABANDONED_0+ nWaitCount) { int nlndex = rc - WAIT_ABANDONED_O; } }

    Read the article

  • Loop crashing program having to do with 2D arrays

    - by user450062
    I am creating an encoding program and when I instruct the program to create a 5X5 grid based on the alphabet while skipping over letters that match up to certain pre-defined variables(which are given values by user input during runtime). I have a loop that instructs the loop to keep running until the values that access the array are out of bounds, the loop seems to cause the problem. This code is standardized so there shouldn't be much trouble compiling it in another compiler. Also would it be better to seperate my program into functions? here is the code: #include<iostream> #include<fstream> #include<cstdlib> #include<string> #include<limits> using namespace std; int main(){ while (!cin.fail()) { char type[81]; char filename[20]; char key [5]; char f[2] = "q"; char g[2] = "q"; char h[2] = "q"; char i[2] = "q"; char j[2] = "q"; char k[2] = "q"; char l[2] = "q"; int a = 1; int b = 1; int c = 1; int d = 1; int e = 1; string cipherarraytemplate[5][5]= { {"a","b","c","d","e"}, {"f","g","h","i","j"}, {"k","l","m","n","o"}, {"p","r","s","t","u"}, {"v","w","x","y","z"} }; string cipherarray[5][5]= { {"a","b","c","d","e"}, {"f","g","h","i","j"}, {"k","l","m","n","o"}, {"p","r","s","t","u"}, {"v","w","x","y","z"} }; cout<<"Enter the name of a file you want to create.\n"; cin>>filename; ofstream outFile; outFile.open(filename); outFile<<fixed; outFile.precision(2); outFile.setf(ios_base::showpoint); cin.ignore(std::numeric_limits<int>::max(),'\n'); cout<<"enter your codeword(codeword can have no repeating letters)\n"; cin>>key; while (key[a] != '\0' ){ while(b < 6){ cipherarray[b][c] = key[a]; if ( f == "q" ) { cipherarray[b][c] = f; } if ( f != "q" && g == "q" ) { cipherarray[b][c] = g; } if ( g != "q" && h == "q" ) { cipherarray[b][c] = h; } if ( h != "q" && i == "q" ) { cipherarray[b][c] = i; } if ( i != "q" && j == "q" ) { cipherarray[b][c] = j; } if ( j != "q" && k == "q" ) { cipherarray[b][c] = k; } if ( k != "q" && l == "q" ) { cipherarray[b][c] = l; } a++; b++; } c++; b = 1; } while (c < 6 || b < 6){ if (cipherarraytemplate[d][e] == f || cipherarraytemplate[d][e] == g || cipherarraytemplate[d][e] == h || cipherarraytemplate[d][e] == i || cipherarraytemplate[d][e] == j || cipherarraytemplate[d][e] == k || cipherarraytemplate[d][e] == l){ d++; } else { cipherarray[b][c] = cipherarraytemplate[d][e]; d++; b++; } if (d == 6){ d = 1; e++; } if (b == 6){ c++; b = 1; } } cout<<"now enter some text."<<endl<<"To end this program press Crtl-Z\n"; while(!cin.fail()){ cin.getline(type,81); outFile<<type<<endl; } outFile.close(); } } I know there is going to be some mid-forties guy out there who is going to stumble on to this post, he's have been programming for 20-some years and he's going to look at my code and say: "what is this guy doing".

    Read the article

  • Lua, game state and game loop

    - by topright
    Call main.lua script at each game loop iteration - is it good or bad design? How does it affect on the performance (relatively)? Maintain game state from a. C++ host-program or b. from Lua scripts or c. from both and synchronise them? (Previous question on the topic: http://stackoverflow.com/questions/2674462/lua-and-c-separation-of-duties)

    Read the article

  • jQuery - $.each loop through json code

    - by Ice
    Due to the way my serverside script outputs I receive multiple JSON objects. {jsonhere}{jsonhere1}{jsonhere2}{jsonhere3} etc.. They aren't seperated by anything. If I would do a split based }{ I would lose those brackets. So is there an outerloop I can put over the regular $.each loop to make this work? Thank you, Ice

    Read the article

  • Trace redirect loop

    - by Michel Krämer
    I have a large PHP application. After I changed some settings I get a redirection loop (i.e. the browser is redirected to the same page over and over again). The problem is that I don't know which command (which line in which PHP file) in this application causes the redirect. Is there a way to trace calls to the header() function? Or - even better - is there a way to trace redirects in PHP? Thanks in advance, Michel

    Read the article

  • Keyboard Input & the Win32 message loop

    - by Tom J Nowell
    How do I handle key presses and key up events in the windows message loop? I need to be able to call two functions OnKeyUp(char c); and OnKeyDown(char c);. Current literature I've found from googling has lead me to confusion over WM_CHAR or WM_KEYUP and WM_KEYDOWN, and is normally targeted at PDA or Managed code, whereas I'm using C++.

    Read the article

  • Matlab plot inside a loop

    - by Macarse
    I am doing something like this: a = [1:100]; for i=1:100, plot([1:i], a(1:i)); end My issue is that the plot is not shown until the loop is finish. How can I show/update the plot in every iteration?

    Read the article

  • Bash edit file and keep last 500 lines

    - by Lizard
    I am looking to create a cron job that opens a directory loops through all the logs i have created and deletes all lines but keep the last 500 for example. I was thinking of something along the lines of tail -n 500 filename > filename Would this work? I also not sure how to loop through a directory in bash Thanks in advance.

    Read the article

  • Grouping records from while loop | PHP

    - by Wayne
    I'm trying to group down records by their priority levels, e.g. --- Priority: High --- Records... --- Priority: Medium --- Records... --- Priority: Low --- Records... Something like that, how do I do that in PHP? The while loop orders records by the priority column which has int value (high = 3, medium = 2, low = 1). e.g. WHERE priority = '1' The label: "Priority: [priority level]" has to be set above the grouped records regarding their level

    Read the article

  • C# Foreach Loop - Continue Issue

    - by Goober
    I have a problem with a continue statement in my C# Foreach loop. I want it to check if there is a blank cell in the datagridview, and if so, then skip printing the value out and carry on to check the next cell. Help appreciated greatly. Here is the code: foreach (DataGridViewRow row in this.dataGridView1.Rows) { foreach (DataGridViewCell cell in row.Cells) { if (cell.Size.IsEmpty) { continue; } MessageBox.Show(cell.Value.ToString()); } }

    Read the article

  • Java loop for a certain duration

    - by portoalet
    Hi, Is there a way I can do a for loop for a certain amount of time easily? (without measuring the time ourselves using System.currentTimeMillis() ?) I.e. I want to do something like this in Java: int x = 0; for( 2 minutes ) { System.out.println(x++); } Thanks

    Read the article

< Previous Page | 30 31 32 33 34 35 36 37 38 39 40 41  | Next Page >