for-loop

Removing Special Characters and bulk renaming

Hello, I am trying to make a shell script to remove special characters, like {}()!,' etc. So far I have referenced a past question I asked here, however I get a strange error message: -bash-3.2$ ./test2.sh ./test2.sh: line 7: unexpected EOF while looking for matching `"' ./test2.sh: line 10: syntax error: unexpected end of file test2....

Seg Fault when initializing array

Hi guys, I'm taking a class on C, and running into a segmentation fault. From what I understand, seg faults are supposed to occur when you're accessing memory that hasn't been allocated, or otherwise outside the bounds. 'Course all I'm trying to do is initialize an array (though rather large at that) Am I simply misunderstanding how to ...

How to iterate initialized enumerated types with Delphi 6 and avoid the "out of bounds" error?

I am using Delphi 6 Professional. I am interfacing with a DLL libraty that declares an enumberated type as follows: TExtDllEnum = (ENUM1 = $0, ENUM2 = $1, ENUM3 = $2, ENUM4 = $4, ENUM5 = $8, ENUM6 = $10); As you can see the initialized values are not contiguous. If I try to iterate the type using a for loop as follows: var e: T...

How Not to Display a seperator or a border after last data of the list?

How Not to Display a separator or a border after last data of the list? I have a list of data which is coded in the form of <ul> and <li> and it is formatted in the way that after every record a border or separator needs to be displayed but after last record this border should not be displayed. I am aware of the fact that it has to be...

sybase for loop in sql

Hi, I need to update a column value in a table based on values from a Other 2 tables. I was able to write a update statement to achieve this: update T3 set col=T1.x from T1,T2,T3 where ... This takes lot of time since the table T3 has more than million records. I would like to get the value v1 from T1 and loop over them and get co...

Quick Question: C# Linq "Single" statement vs "for" loop

I need some clarification. Are these two methods the same or different? I get a little bit confused about when the reference to an object passed in a parameter by value is updated and when a new one is created. I know if that assignment creates a new reference, but what about changing a property? Will both of these methods update the...

Help with For Loop. Values repeating

$teams = array(1, 2, 3, 4, 5, 6, 7, 8); $game1 = array(2, 4, 6, 8); $game2 = array(); if teams[x] is not in game1 then insert into game2 for($i = 0; $i < count($teams); $i++){ for($j = 0; $j < count($game1); $j++){ if($teams[$i] == $game1[$j]){ break; } else { array_push($game2, $teams[$i]);...

Is for ({statements;}; condition; {statements;}) legal C?

Bad style notwithstanding, is it legal C to have a for loop with braces inside the parens? Like this: char *a = "a "; char *b = "b "; for ( { int aComesFirst = 1; char *first = a; char *second = b; }; aComesFirst >= 0; { aComesFirst--; swap(first, second); } ) { printf("%s%s\n", first,...

Is this an F# compiler bug? #2

open System type Foo() = interface Collections.IEnumerable with member x.GetEnumerator () = null type Bar() = interface Collections.IEnumerable with member x.GetEnumerator () = null interface Collections.Generic.IEnumerable<int> with member x.GetEnumerator () = null let xs, ys = Foo(), Bar() ...

Extract a range from NSArray

I need to display 6 views and each view should display 20 items (UIButtons). I have one big NSArray which contains the items for all 6 views. For example, view 1 should be items 0-19, view 2 should be items 20-39. How would i extract the relevant range out of the array? Maybe using NSRange with a length of 20, but the start location w...

php multiple file upload

Hey all, I have a script I'm working out to upload up to 10 files at once. I have 10 seperate inputs in my html: <?php for($i=0;$i<10;++$i) { $num = $i+1; echo ' <span>'.$num.'</span><input type="file" name="photo'.$i.'" /> '; } ?> And then I have my uploader which I have used ...

Allow for loop initialization in GCC and Clang when std={c,gnu}89?

How can I enable for loop initialization when compiling in c89 or gnu89 mode using GCC and Clang? ...

Overloading increment operator, looping, and edge cases.

Hello! I have an enum, that looks like this: enum Suit {Clubs, Diamonds, Hearts, Spades}; I want to overload the increment operator, so I can easily loop over these four dudes. When the variable is Clubs, Diamonds, or Hearts there no issue. Its the Spades condition that is giving me a little trouble. My first instinct was to define...

in or out of a for loop in R - calculating the diagonal product of a matrix

I'm trying to find the maximum diagonal product of 2 digit numbers in a 20x20 matrix. This gives an error message : i <- 17:1 z <- for (j in 1:(18-i)) {b <- max ((x[i,j]*x[i+1,j+1]*x[i+2,j+2]*x[i+3,j+3]))}} But this doesn't: z <- for (i <- 17:1) {for (j in 1:(18-i)) {b <- max ((x[i,j]*x[i+1,j+1]*x[i+2,j+2]*x[i+3,j+3...

Bash Nested Loops, mixture of dates and numbers

Hi, I am trying to output a range of commands with different dates and numbers associated. for each hour eg. Output im trying to do in a loop is: shell.sh filename<number e.g. between 1-24> <date e.g. 20100928> <number e.g. between 1-24> <id> So basically the the above will generate an output done 24 times for each particular day w...

How to express this sum concisely in R?

I have a simple R beginner's question: How do I express the sum below most concisely in R? sum_{i=1}^n a / (a+i) I tried the following, but there must be a better way, without actually calling for: r<-0 for(i in 1:n){ r <- r + (a / (a+i)) } Thanks! ...

In C# is a for(;;) safe and what does it really do?

I found an empty for statement in an existing bit of code and I'm wondering what it does and is it "safe". It just feels wrong. for(;;) { //some if statements and a case statement } Thanks! ...

Using javascript modulus to iterate through text slider with for loop

Hi everyone, I'm new to jQuery and stack overflow, so I'll try to be specific, but please bear with me. I'm trying to create a text slider with associated links from scratch, using modulus to iterate through the list and repeat. Here's the code I'm working with: ul#text { position: relative; margin-bottom: 40px; height: 40px; } ul#tex...

scope of pointers to (local) objects declared within a for loop

Dear all, I'm not sure if the snippet of C++ code below is legitimate or not: std::vector<int*> myints; for (int i = 0; i<N; i++) { int j = i; myints.push_back(&j); } for (int i=0; i<myints.size(); i++) cout<<*(myints[i])<<endl; How does the compiler handle this ? I understand the variable j itself goes out of scope when ex...

SQL: How do I loop through the results of a SELECT statement?

How do I loop through the results of a SELECT statement in SQL? My SELECT statement will return just 1 column but n results. I have created a fictional scenario below complete with the Pseudo code of what I'm trying to do. Scenario: Students are registering for their classes. They submit a form with multiple course selections (ie. s...