Search Results

Search found 12044 results on 482 pages for 'foreach loop'.

Page 40/482 | < Previous Page | 36 37 38 39 40 41 42 43 44 45 46 47  | Next Page >

  • 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

  • Loop through enumeration

    - by Germ
    What is best way to loop through an enumeration looking for a matching value? string match = "A"; enum Sample { A, B, C, D } foreach(...) { //should return Sample.A }

    Read the article

  • Can I use "map" as a substitute for "for each"/"for in"?

    - by John Mee
    For a little while now javascript has the "map" function to loop over arrays. It appears possible to use it as a 'foreach' operator for example: var arr = ['a','b','c'] var doubles = arr.map(function(val){ return val + val }) Is this better or worse than saying for(var i in arr){ ... 50/50: saves having to use the index but adds a callback; it doesn't seem very common so I hesitate to use it but still want to.

    Read the article

  • modify array in loop

    - by SpawnCxy
    Here is the code: $arraya = array('a','b','c'); foreach($arraya as $key=>$value) { if($value == 'b') { $arraya[] = 'd'; //print_r($arraya); //$arraya now becomes array('a','b','c','d') } echo $key.' is '.$value."\n"; } and it will get: 0 is a 1 is b 2 is c And I wonder why 3 is d doesn't show up??

    Read the article

  • Missing $ on loop variable

    - by k0re
    Hi, 1 #!/usr/bin/perl 2 use strict; 3 use warnings; 4 5 my @array = qw[a b c]; 6 foreach my($a,$b,$c) (@array) { 7 print "$a , $b , $c\n"; 8 } I receive following error: Missing $ on loop variable What is wrong? I am using: perl v5.10.1 (*) built for x86_64-linux-thread-multi

    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

  • 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

  • One Line 'If' or 'For'...

    - by aTory
    Every so often on here I see someone's code and what looks to be a 'one-liner', that being a one line statement that performs in the standard way a traditional 'if' statement or 'for' loop works. I've googled around and can't really find what kind of ones you can perform? Can anyone advise and preferably give some examples? For example, could I do this in one line: example = "example" if "exam" in example: print "yes!" Or: for a in someList: list.append(splitColon.split(a))

    Read the article

  • Get Filename in DOS for loop

    - by Murtaza RC
    I have the following For loop in a batch file: for /R c:\test\src %%i IN (*.*) DO ( MOVE %%i C:\test\destination ECHO %%i exit ) The result of the ECHO outputs the entire file path Ex: C:\Foldername\Filename I need to ECHO out only the Filename.Is there a specific command which would give me the filename ? Thanks !

    Read the article

< Previous Page | 36 37 38 39 40 41 42 43 44 45 46 47  | Next Page >