Is there an easier way to break out of nested loops than throwing an exception? (In Perl, you can give labels to each loop and at least continue an outer loop.)
for x in range(10):
for y in range(10):
print x*y
if x*y > 50:
"break both loops"
I.e., is there a nicer way than:
class BreakIt(Exception):...
for (int z = 0; z < alParmValues.Count; z++)
{
//string[] def;
string[] asd = alParmValues[z].ToString().Split(',');//this is of type string.collections and u cant cast it to a arraylist or array
//if (HUTT.clsParameterValues.bCustomObj == false)
string[] def = alMethSign[z].ToSt...
I have created a while-loop in which temporary strings are created (string is updated everytime that loop performs). How can I create an array out of these temporary strings?
...
I'm searching the best way to create a string separated with another in a loop. I mean, for example, SQL reader:
StringBuilder sb = new StringBuilder();
while(reader.Read())
{
sb.Append(reader[0]);
sb.Append("<br />");
}
string result = sb.ToString();
result = result.Remove(result.LastIndexOf("<br />")); // <-
or creating SQL quer...
In Perl I can skip a foreach (or any loop) iteration with a next; command.
Is there a way to skip over an iteration and jump to the next loop in C#?
foreach (int number in numbers)
{
if (number < 0)
{
// What goes here to skip over the loop?
}
// otherwise process number
}
...
When you do stuff like:
for (int i = 0; i < collection.Count; ++i )
is collection.Count called on every iteration?
Would the result change if the Count property dynamically gets the count on call?
...
I have a local class with a method used to build a list of strings and I'm finding that when I hit this method (in a for loop of 1000 times) often it's not returning the amount I request.
I have a global variable:
string[] cachedKeys
A parameter passed to the method:
int requestedNumberToGet
The method looks similar to this:
List...
I'm facing a problem where both recursion and using a loop seem like natural solutions. Is there a convention or "preferred method" for cases like this? (Obviously it is not quite as simple as below)
Recursion
Item Search(string desired, Scope scope) {
foreach(Item item in scope.items)
if(item.name == desired)
r...
ok...in php how do i do this? given the following scenario:
// array of letters
var $letters = array('a', 'b', 'c');
// loop through array and create empty arrays with names like $a, $b, $c
foreach($letters as $letter) {
var $$letter = array();
}
...
In my code jsc.tools is an object containing objects. Each sub-object contains a init() and run() method.
I have the following code running at startup:
for(tool in jsc.tools) {
tool.init();
}
which gives me the error "tool.init is not a function".
A sample of a tool's declaration is:
jsc.tools.sometool = {};
jsc.tools.sometool.run...
Say we have a list {a, a, a, b, b, c, c }
We want to loop through the list and make some kind of change when the item value changes... for example:
prevEmployer = String.empty;
foreach(Person p in PersonList){
if(p.Employer != prevEmployer){
doSomething();
prevEmployer = p.Employer;
}
... more code
}
Is there any alt...
Hello,
I witnessed the following weird behavior. I have two functions, which do almost the same - they measure the number of cycles it takes to do a certain operation. In one function, inside the loop I increment a variable; in the other nothing happens. The variables are volatile so they won't be optimized away. These are the functions...
hi,
i have an object which represents a database table. I want to iterate through this object and print printing each value. What can i use to do this?
i want to do this inside my mxml not actionscript
for each object attribute i want to create an imput field
...
HI,
I need to loop through an array and for each element create a textfield. My problem is how to create a new identifier for each new TextInput
this is my code;
var count:Number = 0;
for (var i:String in columnsData)
{
var myTI:TextInput = new TextInput();
myTI.width = 70;
myTI.height = 25;
myTI.text = columnsData[i];
myTI.name = "my...
I just started learning Ruby and I ran into a problem today.
numResults = /\d+/.match(ie.div(:id, 'results_label').text)
puts "Results found: "+numResults.to_s
while(numResults > 0)
.
. some more code
.
I get this error in my output:
Exception: undefined method `>' for #<MatchData:0x424c6d4>
Which is really strange because I mad...
I'm learning Python as my second programming language (my first real one if you don't count HTML/CSS/Javascript). I'm trying to build something useful as my first real application - an IRC bot that alerts people via SMS when certain things happen in the channel. Per a request by someone, I'm (trying) to build in scheduling preferences ...
Is it possible to exit a C++ loop based on keyboard input without actually having to input something each iteration?
For instance
while(checkkeyboardinput != 'q')
{
do work
}
I feel that this is very easy, but google isn't helping me, and I can't remember how to do this. Thanks for the help.
EDIT: I'm using VS2008
...
Hello everyone,
I'm looking for a way to loop through the columns of a table to generate an output as described below.
The table looks like that:
ID Name OPTION1 OPTION2 OPTION3 OPTION4 OPTION5
1 MyName1 1 0 1 1 0
2 MyName2 0 0 1 0 0
And the output looks like that:
MyName...
How can I (if it is possible) use the Prototype library to loop through all select elements on a page and access the element? In the documentation I found easily shortcuts for referencing elements with certain ids, class names etc. but no reference for elements with certain tag names.
If this is not possible with Prototype, an example w...
Hi - this question feels like it would have been asked already, but I've not found anything so here goes...
I have constructor which is handed a string which is delimited. From that string I need to populate an object's instance variables. I can easily split the string by the delimited to give me an array of strings. I know I can simply...