for-loop

What is the alternate logic to Iterate "for" loop in sending newsletter to many users

What is the alternate logic to Iterate other than "for" loop in sending newsletter to many users as this will exceed maximum time execution time. ...

How do I write a generic for loop for a Java Enum?

Is there a way to write a generic loop to iterate over an arbitrary Enum? For example: public static void putItemsInListBox(Enum enum, ListBox listbox){ for(Enum e : enum.values(){ listBox.addItem(e.toString(), String.valueOf(e.ordinal()); } } You can not do the above, because the Enum class does not have a method call...

Merge several data.frames into one data.frame with a loop

I am trying to merge several data.frames into one data.frame. Since I have a whole list of files I am trying to do it with a loop structure. So far the loop approach works fine. However, it looks pretty inefficient and I am wondering if there is a faster and easier approach. Here is the scenario: I have a directory with several .csv fi...

Why do the following snippets (one using "while" the other using "for") have different behaviors?

I have been trying out some basic exercises involving loops. Can someone tell me why the following snippets have different outputs? While Loop while (i<3) { while(j<3) { printf("(%d %d) ",i,j); j++; } i++; } Output (0 0) (0 1) (0 2) For Loop for(i=0;i<3;i++) { for(j=0;j<3;j++) ...

Xcode "infinite loop" inconsistency

When running this code under debug in the iPhone simulator, it correctly exits with r==4 after 5 iterations of the loop:- int r; for (r = 0;;r++) { if (r == 4) break; } Without the braces, it exits with r==1 after 1 iteration:- int r; for (r = 0;;r++) if (r == 4) break; Without the braces, but with a test ex...

Two Counts for the for loop?

Can you have two counts with for loop? Example: for( var count1 = 0, count2 = 0; count1 < 5; count1++, count2++ ) { } If not, what would be a good way to handle two separate counts other than using two loops? ...

Terminating the app due to uncaught exception in Objective-C for iPhone app

Hello, i've written a for loop in Objective-C, This is how my code looks like NSString *string = [NSString stringWithContentsOfFile=@"/Users/Home/myFile.doc"]; NSString *seperator=@"\n"; NSArray *mainarray = [string componentsSeparatedByString:seperator]; // Since i want to parse each element of mainarray for(NSString *s in mainarray) {...

Can all 'for' loops be replaced with a LINQ statement?

Is it possible to write the following 'foreach' as a LINQ statement, and I guess the more general question can any for loop be replaced by a LINQ statement. I'm not interested in any potential performance cost just the potential of using declarative approaches in what is traditionally imperative code. private static string SomeMeth...

R-thonic replacement for simple for loops containing a condition

I'm using R, and I'm a beginner. I have two large lists (30K elements each). One is called descriptions and where each element is (maybe) a tokenized string. The other is called probes where each element is a number. I need to make a dictionary that mapsprobes to something in descriptions, if that something is there. Here's how I'm going...

Loops in C - for() or while() - which is BEST?

for() or while() - which is BEST? for (i=1; i<a; i++) /* do something */ OR i=1; while (i<a) { /* do something */ i++; } ...

Evaluating variable within R loop

I'm trying to iteratively generate some functions using a For Loop: # Create a list to hold the functions funcs <- list() funcs[] # loop through to define functions for(i in 1:21){ # Make function name funcName <- paste( 'func', i, sep = '' ) # make function func = function(x){x * i} funcs[[funcName]] = func ...

Null check in an enhanced for loop

What is the best way to guard against null in a for loop in Java? This seems ugly : if (someList != null) { for (Object object : someList) { // do whatever } } Or if (someList == null) { return; // Or throw ex } for (Object object : someList) { // do whatever } There might not be any other way. Should they...

unexpected list appearing in python loop

I am new to python and have the following piece of test code featuring a nested loop and I'm getting some unexpected lists generated: import pybel import math import openbabel search = ["CCC","CCCC"] matches = [] #n = 0 #b = 0 print search for n in search: print "n=",n smarts = pybel.Smarts(n) allmol = ...

Nested loops always confuse me

So I have a loop to be nested inside another loop based on two queries. I have the first loop working fine- $sql_categories = mysql_query("SELECT * FROM $categories_table"); $results = mysql_query("SELECT * FROM $events_table"); while ($num_rows = mysql_fetch_assoc($sql_categories)) { extract($num_rows); echo "<h2>...

C - Abbreviated for loop executed only once

I have command line utility written in ANSI C on a Mac with a function to create a bubble sorted array for a single-linked list. I declared the loop variables. int a = 0; int b = 0; I wrote the bubble sort for loops in the abbreviated style (i.e., leaving the variable initialization empty). for ( ; a < size; a++) for( ; b < s...

How to jump to Next statement from For or For Each (like braces but in vb) in Visual Studio 2008

Does anyone know the keyboard shortcut to jump from the start of a For / For Each (or If, While, etc.) block to the end of it in visual studio if you're using vb.net? I found the following which I thought would work but doesn't : http://stackoverflow.com/questions/1501921/go-to-matching-brace-in-visual-studio Following the comment ther...

When implementing an infinite loop, is there a difference in using while(1) vs for(;;) vs goto (in C)?

When implementing an infinite loop, is there a difference in using while(1) vs for(;;) vs goto? Thanks, Chenz ...

Exception in WCF client

Hi, I am using WCf service in my windowsApplication... I got the exception in my client When i am trying to add items in Listbox by using ForEach Loop... The exception is "Collection was modified enumuration may not execute". How shall i solve this exception.... And my code is, foreach (ClsPC pc in iclsobj.GetPC()) ...

java repeat character

Hi Guys, I am a java beginner, please keep that in mind. I have to make a program that reads a number, and then displays that amount of exclamation mark "!". This is what i have: import java.util.Scanner; import java.io.PrintStream; class E_HerhaalKarakter1 { PrintStream out; E_HerhaalKarakter1 () { out = new PrintStream(System...

Rotate with screen object ?

Actually i am doing a project for my university Witch is i have to Analysis a game so i found a problem which is character rotated has problem so i recommend to use the mouse what other suggestion i can use for example add object on screen so need to know if i add object on screen why this will be improve the game and what other docum...