loops

Condition order in while loop

Hello everyone, First of all, before I begin, I am using VC++ 2008 professional, running an Intel core2 on windows OS. I also know that this code will NEVER be executed on anything other than a core2/corei7 running Windows. I have a while loop with 2 conditions that looks something like this: note: this is a much simplified version. ...

What does a while after a print mean in Perl?

I am new to Perl. Know a little bit of C though. I came across this snippet in one of our classroom notes : $STUFF="c:/scripts/stuff.txt"; open STUFF or die "Cannot open $STUFF for read :$!"; print "Line $. is : $_" while (<STUFF>); Why is the while after the print statement? What does it do? ...

.NET / C# - Proper Method to Use Here - LINQ

I'm a total newb to LINQ. Here is the code I have so far: public class Folder { public Folder(string path) { string[] files = Directory.GetFiles(path); IList<FileInfo> fis = new List<FileInfo>(); files.SomeMethod(x => fis.Add(new FileInfo(x))); } } What is the correct method name to replace SomeMet...

Windows batch file for renaming file at specified interval

I would like to write a windows batch file for the purpose of renaming a file every 25 seconds. I would also like the batch file to terminate after 300 seconds have passed. How would I go about doing this? Here is what I have thusfar. START RENAME test.g test.go SLEEP 25 RENAME test.go test.g GOTO START ...

Stuck in a loop ! :o

Hi. I'm trying to implement my own List system in Java. the List class file : package RoutingDemo.List; /** * A 2-way Linked-List to store generic elements. * */ public class List { /* Instance Variables --------------------------------------------------------------------------- */ /** * Reference to el...

How to loop through an table and turn rows into objects using nokogiri

I want to use nokogiri to loop through a html and create an object corresponding to every row. I am able to define the root xpaths where I want the data to fill the object varibles comes from but I dont know how to group these as an object. My code is below. I know it doesn't work but I dont know what direction to go to make it work. ...

Another jQuery noob question about functions

I want to "functionalize" more of my jQuery code, instead of writing little standalone snippets. Here's an example. Let's say I have some li's that I'd like to use as triggers, like so: <li class="alpha-init" id="a-init">A</li> <li class="alpha-init" id="b-init">B</li> <li class="alpha-init" id="c-init">C</li> And some stuff I'd like ...

Is it possible to refactor this MySQL stored procedure loop?

Hi! I have a loop in MySQL stored procedure where i insert record almost for each iteration. Well known problem is that inserting row-by-row is inefficient and i'd rather see inserts with multiple value lists instead. Pseudo-example of current procedure: CREATE PROCEDURE p_foo_bar() BEGIN DECLARE foo VARCHAR(255); DECLARE my_cursor...

LINQ To SQL - What is the most efficient way to loop through master/detail?

The only thing I can find when dealing with master/detail and LINQ is through databinding. However, I am using LINQ to query my data and will need to manually loop through results without the need for databinding. My final intent is to loop through a master result set, get a grouped list of children, and output the master/detail data as ...

how to loop through rows columns in excel VBA Macro

Hi, I am trying to create a macro that has a loop which copies a function down column 1 (VOL) and another function down column 2 (CAPACITY) for each Station. This is what I have so far: Sub TieOut() Dim i As Integer Dim j As Integer For i = 1 To 3 For j = 1 To 3 Worksheets("TieOut").Cells(i, j).Value = ...

variable allocation in a nested loop question

because obj, the playingCard object is created inside a nested for loop does that mean after the second for loop completes, obj gets deallocated from the stack each time? and a small side question, does a compiler use the stack (similar to recursion) to keep track of loops and nested loops? for(int c = 0;c<nElems;c++) { for(int...

How to make absolute cell ref in loop work and skipping over a column in loop?

I ALMOST got my code working but there are still two things wrong with it (two major things anyway). 1) The absolute cell ref. is not working as it does in Excel. I want for example $A5 but instead of changing to A6 A7 etc., it stays A5 throughout the loop. 2) There is a third column that I need to skip over. I only need my loop to wri...

Continue in nested while loops

In this code sample, is there any way to continue on the outer loop from the catch block? while { // outer loop while { // inner loop try { throw; } catch { // how do I continue on the outer loop from here? continue; } } } ...

is there a difference in the runtime of the following:

Is there a difference in the runtime of the following two snippets? SNIPPET 1: for ( Object obj : collection ) { step1( obj ); step2( obj ); step3( obj ); } SNIPPET 2: for ( Object obj : collection ) { step1( obj ); } for ( Object obj : collection ) { step2( obj ); } for ( Object obj : collection ) { step3...

"<" operator error

Why is the ( i < UniqueWords.Count ) expression valid in the for loop, but returns "CS0019 Operator '<' cannot be applied to operands of type 'int' and 'method group'" error when placed in my if? They are both string arrays, previously declared. for (int i = 0;i<UniqueWords.Count;i++){ Occurrences[i] = Words.Where(x => x.Equals(Uni...

How can I access the nth byte of a binary scalar in Perl?

Thanks to everyone in advance. I'd like to access the nth byte of a binary scalar. For example you could get all the file data in one scalar variable... Imagine that the binary data is collected into scalar... open(SOURCE, "<", "wl.jpg"); my $thisByteData = undef; while(<SOURCE>){$thisByteData .= $_;} close SOURCE; $thisByteData...

Cascading Rails Loop Not Displaying Correct Data

I have the following code in my layout file: <% @families = ProductFamily.find(:all, :include => :products) %> <% @families.each do |f| %> <h2><%=h f.name %></h2> <ul> <% f.products.each do |product| %> <li><%=h product.name %></li> <% end %> </ul> <% end %> Two things: I doubt this follows standard MVC pr...

PHP - Looping through $_FILES to check filetype

My first question on SO, thanks. :) I'm developing a support issue logging system for my company and it must allow for files to be uploaded aswell as any problems submitted to our database. There could be from 0-6 different uploads to check, along with a support issue. I've managed to get an accurate variable of how many files there is ...

Loop Boundries and Performance Issues

Hi, Suppose we want to loop through all the items in a dropdown list and no item is added or removed while we are looping. The code for it is as follows: for (int i = 0; i < ddl.Items.Count; i++) { if (ddl.Items[i].Text == text) { found = true; break; } } If it is changed to this: for (int i = 0, c = ddl....

Batch Looping A Model With Ruby

I know of the find_in_batches method for ActiveRecord, but this doesn't allow me to set my :order or :limit. I am trying to loop through my data, and for every 6 items I want to wrap them in a <div>. I was trying to whole... <% i = 0 @media.each do |media| %> <% if i%6 %><div class="section"><% end %> [...] <% if i%6 %></div><% en...