string strLine;//not constant
int index = 0;
while(index < strLine.length()){//strLine is not modified};
how many times strLine.length() is evaluated
do we need to put use nLength with nLength assigned to strLine.length() just before loop
...
I am profiling an application suddenly using a lot of memory, and i am getting this:
sun.java2d.loops.ProcessPath$Point
As being allocated almost 11.000.000 times.
What is it, and is there a solution to this?
...
I'm looking for a good tutorial on writing and designing loops. I understand the basics of loops but nested loops give me a lot of trouble. To give you and idea, the following pattern below was kind of difficult for me to figure out.
1
12
123
1234
12345
123456
...
Say i have an array of values:
string[] text = new string[] {"val1", "val2", "val3", "val4", "val5"};
Then i have a basic loop:
for(int i=0;i<=30;i++) {
Console.WriteLine(i + " = " + text[i])
}
Obviously this will cause an out of bounds exception, so what i want to do is when the counter reaches the upper bound of the array the...
Noob
I am trying to write a script that gives a running balance. I am messing up on the elementary declared functions of python.
I need it too:
accept a balance via input
append a list of transactions
take those out one by one in the order they were input
print a running total
use pyhtmltable to make the output in html table rea...
I've found myself writing
for(int i=0;i<myvec.size();i++)
myvec[i]->DoWhatever(param);
a lot, and I'd like to compress this into a foreach statement, but I'm not sure how to get param in there without going super-verbose. I've also got things like
for(int i=0;i<myvec.size();i++)
if(myvec[i]->IsOK())
myvec[i]->DoWhatever(p...
int n = 5;
for(int i = 0;i!=n;i++)//condition !=
{
//executing 5times
}
int n = 5;
for(int i = 0;i<n;i++)//condition <
{
//executing 5times
}
Which one is preferred?
This was example from "Accelerated C++
: practical programming by example /
Andrew Koenig, Barbara E. Moo." Just
wanted to know why the Author prefers
the fi...
Is there a way in Java's for-each loop
for(String s : stringArray) {
doSomethingWith(s);
}
to find out how often the loop has already been processed?
Aside from using using the old and well-known for(int i=0;i<boundary;i++)-loop, is the construct
int i = 0;
for(String s : stringArray) {
doSomethingWith(s);
i++;
}
the only wa...
I want to display items as follows,
<td1> <td2> <td3> <td4>
1 7 13 19
2 8 14 20
3 9 15 21
4 10 16 22
5 11 17 23
6 12 18
I am getting data (from 1......23) in a single column from database. N...
I have a script that loops through a series of four (or less) characters strings. For example:
aaaa
aaab
aaac
aaad
If have been able to implement it with nested for loops like so:
chars = string.digits + string.uppercase + string.lowercase
for a in chars:
print '%s' % a
for b in chars:
print '%s%s' % (a, b)
...
I am quite new in Perl and I woud like to know which of the following loops is more efficient:
my @numbers = (1,3,5,7,9);
foreach my $current (@numbers){
print "$current\n";
}
or
my @numbers = (1,3,5,7,9);
foreach (@numbers){
print "$_\n";
}
I want to know this in order to know if the use of $_ is more efficient because is...
Hi, I was working with some C# code today in the morning and I had something like:
foreach(DataRow row in MyMethod.GetDataTable().Rows) {
//do something
}
So, as I dont have a full understanding of the language framework I would like to know if GetDataTable() gets called each time an iteration is done or if it just gets called once an...
i have:
for i in range(2,n):
if(something):
do something
else:
do something else
i = 2 **restart the loop
But that doesn't seem to work. Is there a way to restart that loop?
Thanks
...
Does anyone know of an algorithm to find if a linked list loops on itself using only two variables to traverse the list. Say you have a linked list of objects, it doesn't matter what type of object. I have a pointer to the head of the linked list in one variable and I am only given one other variable to traverse the list with.
So my...
How can polymorphism replace an if-else statement or Switch inside of a loop? In particular can it always replace an if-else? Most of the if-thens I use inside of loops are arithmetic comparisons. This question is spawned from this question.
int x;
int y;
int z;
while (x > y)
{
if (x < z)
{
x = z;
}
}
How woul...
<edit>
Thanks to everyone who has answered so far. The zip and os.path.join are really helpful. Any suggestions on ways to list the counter in front, without doing something like this:
zip(range(len(files)), files, directories)
</edit>
Hi,
I'm in the process of learning Python, but I come from a background where the following pseudo...
So for a list that has 1000 elements, I want to loop from 400 to 500. How do you do it?
I don't see a way by using the for each and for range techniques.
...
Anyone knows how to access the index itself so for a list like this:
ints = [8,23,45,12,78]
when I loop through it using a for loop, how do I make access the for loop index, from 1 to 5 in this case?
...
Is there a way to do foreach style iteration over parallel enumerables in C#? For subscriptable lists, I know one could use a regular for loop iterating an int over the index range, but I really prefer foreach to for for a number of reasons.
Bonus points if it works in C# 2.0
...
So I can start from len (collection) and end in collection[0].
EDIT: Also sorry forgot to mention, I also want to be able to access the loop index.
...