loops

How to scan in two arrays from user??

I'm relatively new to programming and I have to write a function that reads in input from the user and to fill two arrays then compare them. I guess what I'm confused on is how to read in both arrays. This is what I'm supposed to do, Write a table_diff fuction that compares two arrays of integers and returns the subscript of the first ...

Using loops to create arrays

I am extremely new at php and I was wondering if someone could help me use either a for or while loop to create an array 10 elements in length ...

Using foreach (...) syntax while also incrementing an index variable inside the loop

When looking at C# code, I often see patterns like this: DataType[] items = GetSomeItems(); OtherDataType[] itemProps = new OtherDataType[items.Length]; int i = 0; foreach (DataType item in items) { // Do some stuff with item, then finally itemProps[i] = item.Prop; i++; } The for-loop iterates over the objects in items, b...

how to loop files in linux from svn status

As being quite a newbie in linux, I have the follwing question. I have list of files (this time resulting from svn status) and i want to create a script to loop them all and replace tabs with 4 spaces. So I want from .... D HTML/templates/t_bla.tpl M HTML/templates/t_list_markt.tpl M HTML/templates/t_vip.tpl M HTML...

Vb6: Need some help with a loop

So I have a loop that's supposed to do three things, go through a text file line by line, the text file contains pathnames and filenames(C:\Folder\file1.txt) If the line contains a certain string, it then copies a file to that location, renames it to what it is named in the text file, and then replaces a string within the copied file(sti...

Most elegant looping construct?

Sorry for the newb question. I'm still learning programming. So I'm using C++, and I need to do something like this: int n; do { n = get_data(); if(n != -1) send(n); } while(n != -1); This is just a sketch. Anyway it doesn't feel real elegant. I have to have my test twice. I could just test once and set a flag, bu...

Problem inserting multiple rows quickly to Oracle database from VB

I'm trying to insert multiple rows, one after another, to a database. Here is the relevant code. Private ConnectionString As String = "Provider=OraOLEDB.Oracle;Data Source=(DESCRIPTION=(CID=GTU_APP)(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=xxx)(PORT=xxx)))(CONNECT_DATA=(SID=xxx)(SERVER=DEDICATED)));User Id=xxx;Password=xxx;" Private SQ...

Using a batch file to loop through Oracle SQL scripts

I have two SQL scripts which get called within a loop that accept a number parameter. Here is what I'm currently using: for /l %%i in (1, 1, 51) do ( sqlplus u/p@name @script.sql a%%i.html %%i sqlplus u/p@name @script.sql b%%i.html %%i ) Everything works fine, but it seems like a waste of time and resources to connect twice fo...

How do you iterate through custom keys in web.config?

Hi, is it possible to create my own custom keys in the asp.net web.config file and iterate through them with C#? How do you do both (where do I put the key? what format?)? I have an application for an intranet that does certain things based upon the IP address of the client. Instead of hard coding those in the codebehind file, I thou...

Functional alternative?

Hi all, As I continue my quest of learning functional programming, I've come to wonder if there may be alternatives to my default "procedural" way of thinking. To be more specific, I'm looking at a function I wrote. Here is what it does: Swap two elements of an unordered list of numbers, such that one of the elements is now in the r...

How to update C# hashtable in a loop?

I'm trying to update a hashtable in a loop but getting an error: System.InvalidOperationException: Collection was modified; enumeration operation may not execute. private Hashtable htSettings_m = new Hashtable(); htSettings_m.Add("SizeWidth", "728"); htSettings_m.Add("SizeHeight", "450"); string sKey = ""; string sValue = ""; foreach (D...

Event handlers inside a Javascript loop - need a closure?

I'm working with a bit of html and Javascript code that I've taken over from someone else. The page reloads a table of data (via an asynchronous request) every ten seconds, and then re-builds the table using some DOM code. The code in question looks something like this: var blah = xmlres.getElementsByTagName('blah'); for(var i = 0; i < ...

foreach or Repeater - which is better?

I'm building a website in ASP.Net, using MVC, and need to list a set of results. Both of the following work as I want them to but I'm wondering which is faster, cleaner and/or better - or if another option entirely would be more appropriate? Note: ViewData.Model is of type IEnumerable<Thing> and I need to display more attributes than Na...

Creating a list of objects in Python

Hi, I'm trying to create a Python script that opens several databases and compares their contents. In the process of creating that script, I've run into a problem in creating a list whose contents are objects that I've created. I've simplified the program to its bare bones for this posting. First I create a new class, create a new ins...

What is a good way to create a variably sized group to be looped over in Excel 2003?

I have a procedure that is run for a lot of items, skipping over certain items who don't meet a criterion. However, I then go back and run it for some of the individuals who were missed in the first pass. I currently do this by manually re-running the procedure for each individual person, but would ideally like a solution a little more...

How to trigger a function once, and only once...?

I often want to trigger a certain function just once, but I need to trigger it from within another function that gets repeatedly called. For instance, taking a snapshot of something for later use. I usually do it by setting a global boolean. I'm wondering whether the way I do it is actually best way? I seem to recall reading that glob...

Why doesn't this javascript (jQuery) go into an infinite loop?

I was reading the great article about binding and unbinding events (because I am a js beginner using jQuery) on Karl Swedberg's blog, and I became totally puzzled at this part of the code (simplified for brevity): function addItemUnbind() { $Add a button but it won't have it's event added; addItemUnbind(); }); Why is...

jQuery Closures, Loops and Events

I have a question similar to the one here: http://stackoverflow.com/questions/341723/event-handlers-inside-a-javascript-loop-need-a-closure#341759 but I'm using jQuery and the solution given seems to fire the event when it's bound rather than on click. Here's my code: for(var i in DisplayGlobals.Indicators) { var div = d.createElem...

How do I skip to a specific input line in Perl?

I want to skip to the first line that contains "include". <> until /include/; Why does this not work? ...

FLASH Auto Looping Disable

Hi Guys, I have an animation and I want it to play it just only once. From where can I set so when I export to SWF the default will be AUTO LOOPING disabled. Thanks ...