for-loop

conditional loop conversion in Scala

I'd like to convert a piece of Java code which looks like the following into Scala: for (Iterator<Task> it = tasks.iterator(); it.hasNext() && workflow.isAutoRun();) { Task task = it.next(); if (!runTask(task)) break; } I am not a fan of the scala for-comprehensions (not that I know how to break the iteration anyway) and I've ...

For list unless empty in python

I've been writing a lot of constructs like this the past couple of days: list = get_list() if list: for i in list: pass # do something with the list else: pass # do something if the list was empty Lot of junk and I assign the list to a real variable (keeping it in memory longer than needed). Python has simplified a lot...

Base class for windows service

My new project has a design in which there are number windows services for performing different tasks. I have been given a task to create base class from which all of the windows service will inherit. This base class will perform common functions like creating instances of other windows services by iterating through the config file (may ...

(i'm close - i think) Python loop through list of subdomains with selenium

Hi, starting with a base URL, I'm trying to have selenium loop through a short list of subdomains in csv format (ie: one column of 20 subdomains) and printing the html for each. I'm having trouble figuring it out. Thanks! from selenium import selenium import unittest, time, re, csv, logging subds = csv.reader(open('listofsubdomains.txt...

Is possible to use nanosleep in a infinite loop with select()?

Hi, I have a C program that do recv/send operations from/to socket using a for(;;) loop and a select() to monitor the file descriptor. I need also this program to send a packet every 80msec to a packet, how can I implement this? Maybe I can use a fork() and the child process simply write an ack in one of the file descriptor monitored b...

Jquery using wrapAll

I need to find all the p tags inside all the divs with a class of someClass and wrap them with another div. This is how the beginning mark up would look like : <div class="someClass"> // Lots of different tags generated by the site <p>Some text</p> <p>Some text</p> <p>Some text</p> <p>Some text</p> </div> <div class="som...

deleting an object in a loop that runs through the range of the list??

I have a list composed of [start position, stop position, [sample names with those positions]] My goal is to remove the duplicates with exact start and stop positions and just add the extra sample to the sample names section. The problem I'm encountering is that when I delete from the list, I end up with an out of range error, because...

OCaml - For Loop inside If Statement

Coming from a Java and C background, grasping some concepts of Ocaml has been quite interesting. One such is, getting a/multiple statement to run inside a for loop. let test_method (x:vector list)(vec:vector) = if List.length x != 0 then {a=0.;b=0.} (* Return a vector of 0,0 *) else for i = 0 to List.l...

How to generate a range of numbers in PHP with increment of 0.25?

I want to generate a list of numbers with a 0.25 difference between them, e.g 0 0.25 0.50 0.75 1 1.25 ..... 9.75 10 How can this be done? ...

Converting an input word number (like seven) into a character (like @)

so if the user types down seven with Scanner, @@@@@@@ (7) will be the output. I'll have to use a for loop statement but I can at least figure out that much. Just need help with figuring out a way to convert word numbers into a numerical number and finally into a random character. ...

What is a neat way of breaking out of many for loops at once?

Suppose I need to break out of three or four nested for loops at once at the occurence of some event inside the innermost loop. What is a neat way of doing that? what I do is use flags like this: int i, j, k; int flag1 = 0; int flag2 = 0; for (i = 0; i < 100; i++) { for (j = 0; j < 100; j++) { for (k = 0; k < 100; k++) { ...

how to get value of checked element in for loop

Hi I am working to get each value of the checked element and post them to php. But it only gets first value of just one checked item. here is $("#conf").click(function(){ var count = $("input:checked").length; for(i = 0; i < count; i++) { a = $("input:checked").val(); $.post("reqs.php?act=confirm", { ID: a }, fu...

How to add trailing dots?

Hi, I am making an application in which the label keeps scrolling up. The problem I have is I want to do right alignment so that I get "." in a sequence like Basket.............. Ball................ keyboard............ Can anyone help me with this please? I have tried this, but it isn't working for me, for (int u = textBox1.Length...

UserControl array, each control has a method to set the text of a label there, but getting a NullReferenceException. Help!

So, I create an array: TorrentItem[] torrents = new TorrentItem[10]; The TorrentItem control has a method called SetTorrentName(string name): private void SetTorrentName(string Name) { label1.Text = Name; } I'm using a for loop to populate 10 TorrentItems like so: private TorrentItem[] GetTorrents() { TorrentItem[] torrent...

weird for loop behaviour in firefox 3.5.3

I maybe doing something wrong, but this seems quite weird to me: for(i=1; i < 5; i++){ alert(i) } in before mentioned firefox version gives me five counts of i. the question simply is: what the hell? thanks! SOLUTION: ok, it was my own mistake. i actually had an alert after the one in the loop which displayed number 5 :) thanks all...

Problem using break command in Python tutorial

I'm following the python tutorial at their site and I'm currently at the break continue section. I just tried this sample code. >>> for n in range(2, 10): ... for x in range(2, n): ... if n % x == 0: ... print n, 'equals', x, '*', n/x ... break ... else: ... # loop fell through without fin...

What is the pythonic way to detect the last element in a python 'for' loop?

I'd like to know the best way (more compact and "pythonic" way) to do a special treatment for the last element in a for loop. There is a piece of code that should be called only between elements, being suppressed in the last one. Here is how I currently do it: for i, data in enumerate(data_list): code_that_is_done_for_every_element ...

Refactor Django template forloop

I feel like there has to be a cleaner way to do somthing like this. I have 15 or so objects that list out with three on a row. Anyone know a better solutions. <ul> {% for object in object_list %} <li {% ifequal forloop.counter 1 %}class="first"{% endifequal %} {% ifequal forloop.counter 4 %}class=...

Why does bash ignore newlines when doing for loop over the contents of a C-style string?

Why does the following... c=0; for i in $'1\n2\n3\n4'; do echo iteration $c :$i:; c=$[c+1]; done print out... iteration 0 :1 2 3 4: and not iteration 0 :1: iteration 1 :2: iteration 2 :3: iteration 3 :4: From what I understand, the $'STRING' syntax should allow me to specify a string with escape characters. Shouldn't "\n" be in...

Multiple initialization in C# for cycle

How can I (if it is possible at all) intialize multiple variables of different type in C# for cycle? Example: for (MyClass i = 0, int j = 1;j<3;j++,i++) ...