loops

How do you loop through a string in Ruby?

Pretty simple question from a first-time Ruby programmer. How do you loop through a slab of text in Ruby? Everytime a newline is met, I want to re-start the inner-loop. def parse(input) ... end ...

Flash AS3 timer question

Hi I have got a timerEvent that adds 25 movieclips to the stage and animates them from x:0,y:0, this all works fine! What i would like to do is assign each movie clip a y value of 25px more than the last movieClip added to the stage. I did a little test by trying to increment a number value each time the timer did a loop but it didnt inc...

sql2000 loop in a stored procedure

I am very new to SQL i can work with basic statements fairly easily but i haven't figured out loops yet. Foreach(JobHeaderID AS @OldJobHeaderID in dbo.EstimateJobHeader WHERE EstimateID=@OldEstimateID) { INSERT EstimateJobHeader (ServiceID,EstimateID) SELECT ServiceID, @NewEstimateID FROM EstimateJobHeader WHERE EstimateI...

Howto Restart Loop in C++ (Finding Unique Sequence Over Random Runs)

Dear all, The following codes try to generate random strings over K runs. But we want the newly generated strings to be totally different with its reference string. For that I tried to use "continue" to restart the random string generation process. However it doesn't seem to work. What's wrong with my approach below? #include <iostre...

Clean vector every loop iteration. What is the most memory efficient way?

Hi, I have a question about the std::vector. I have a very memory intensive algorithm where I forsee that predicting vector sizes and reserving enough memory for the vectors in advance will help me a lot with reducing memory usage. Which of the following is better: for ( ... ) { std::vector<Type> my_vector; my_vector.reserve(stuff...

A better way of writing this : growing array

Was looking at some code earlier, and am thinking that there has to be a more elegant way of writing this.... (returnVar.Warnings is a string array, it could be returned as any size depending on the number of warnings that are logged) For Each item In items If o.ImageContent.ImageId = 0 Then ReDim Preserve returnVar.Warning...

Rails 'params' variable

In reference to this I've created a question in a webform like this: <div class="form_row"> <label for="features[]">Features:</label> <% [ 'scenarios', 'role_profiles', 'private_messages', 'polls' ].each do |feature| %> <br><%= check_box_tag 'features[]', feature, (params[:features] || {}).in...

Creating Map from Alternate Key Value Input

Dear all, I have a data that looks like this: >day11:1:356617 ACTTCTGATTCTGACAGACTCAGGAAGAAACCAT >day11:2:283282 CTCAGCCCGTAGCCCGTCGGTTCCGGAGTAAGTT >day11:3:205058 NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN >day11:4:202520 AGTTCGATCGGTAGCGGGAGCGGAGAGCGGACCC >day11:5:107099 AGGCATTCAGGCAGCGAGAGCAGAGCAGCGTAGA >day11:6:106715 CTCTTTGCCCCATCTACTGC...

Use "mysql_fetch_row" to retrieve results from database and insert into array using PHP and mysqli?

Hi, I need to retrieve data from several rows and then insert the results into an enumerated array so then I can use a "for" loop to echo it... I have this (I already connected to the database): $genres_sql = 'SELECT genreID FROM genres WHERE imdbID = ?'; if ($stmt->prepare($genres_sql)) { // bind the query parameters $stmt->bind_par...

What is the special case with the foreach loop that eliminates bounds checking?

What is the special case with the foreach/for loop that eliminates bounds checking? Also which bounds checking is it? ...

PHP nested loop behaving unexpectedly

I have an array which contains the categories for a particular article ($link_cat). I'm then using mysql_fetch_array to print out all of the categories available into a list with checkboxes. While it's doing this I want it to compare the value it's on, to a value from the other array. If there is a match, then it means that one of the ca...

What's the cleanest way to walk and unwalk a std::vector using iterators?

I have a situation where I'm marching through a vector, doing things: std::vector::iterator iter = my_list.begin(); for ( ; iter != my_list.end(); ++iter ) { if ( iter->doStuff() ) // returns true if successful, false o/w { // Keep going... } else { for ( ; iter != m_list.begin(); --iter ) // ...This won't work......

What is the difference between for..in and for each..in in javascript?

What is the difference between for..in and for each..in statements in javascript? Are there subtle difference that I don't know of or is it the same and every browser has a different name for it? ...

Kernel.loop method requires 'do' - semicolon not allowed?

LOOP This works with do: x=0 loop do puts x; x+=1; break if x == 100 end but not with a semicolon: x=0 loop; puts x; x+=1; break if x == 100 end UNTIL However, this works with 'do': until x == 100 do puts x; x+=1 end and with a simicolon: until x == 100; puts x; x+=1 end With certain Ruby syntax I have a choice of u...

Erroneous Data Retrieved From ListView

I am having some trouble with my program logic that loops through a collection of data that exists in two separate ListViews. After looping though and extracting the data from the ListView, I then add everything into a comma delimited text file (CLOSEULDCONFIG.TXT). The first time that I execute this logic, everything works as it shoul...

Doesn't JavaScript support closures with local variables?

I am very puzzled about this code: var closures = []; function create() { for (var i = 0; i < 5; i++) { closures[i] = function() { alert("i = " + i); }; } } function run() { for (var i = 0; i < 5; i++) { closures[i](); } } create(); run(); From my understanding it should print 0,1,2,3,4 (isn't this the conc...

looping to make upper case characters for a vector<struct> element

Upon debugging i had thought i did it right. But it was only the first member as the first element in the vector that was corrected. while ( !inFile->eof() ) { getline( *inFile, str1, ',' ); sStruct.str1 = str1; getline( *inFile, str2, ',' ); sStruct.str2 = str2; getline( *inFile, str3, ',' ); sStruct.str3 ...

How to implement a fixed-step loop?

I am attempting to create a fixed step loop in my program, but for some reason I just can't seem to get it to work properly. Basically what I need is a loop that does: while(!over) { Update(elapsedtime); Draw(elapsedtime); } or something similar, with a . I've tried using Thread.Sleep but I'm not so sure it gave me a real fixe...

How do I nest xsl:for-each from different parts of the xml document?

I am putting an XSL together than will create a NAnt build script using as input an XML file that defines all of the items that need to be built. We have a lot of very similar projects with standard layouts and defined standards for handover areas and so having an XML file that defines what the developers want to happen rather than desc...

Game loop that won't stop waiting for user input

I've started fiddling with C to improve my programming skills, and decided to try and implement a Tetris game. Nothing too fancy, it'll run on the console. I never implemented a game that keeps running despite user input, and didn't figure out I'd have to deal with this problem until I started thinking about the game algorithm. Googl...