loops

How can I use arrays in unix shell?

Hi, I use code in !/bin/sh like this: LIST1="mazda toyota honda" LIST2="2009 2006 2010" for m in $LIST1 do echo $m done As you can see this currently prints out only the make of the car. How can I include the year to each "echo" based on the same positions so that I get results like: mazda 2009 toyota 2006 honda 2010 ? ...

Is there any significant difference between nesting a while loop in a while loop and nesting an if-else loop in a while loop? (C++)

EDIT: I forgot to add the loop part of the second code. Looking at the two code styles while(some_loop_cont_val) { while(pre_x is not done) { //do action pre_x } //do action x } and while(some_loop_cont_val) { if(pre_x is not done) { //do action pre_x } else { //do action x...

Show Attached Image to Post on Wordpress

Hello. How i can show attached images of my posts on Wordpress? ...

Generating names iteratively in R for storing plots

I'm using R to loop through a data frame, perform a calculation and to make a plot. for(i in 2 : 15){ # get data dataframe[,i] # do analysis # make plot a <- plot() } Is there a way that I can make the plot object name 'a', using the value of 'i'? For example, a + "i" <- plot(). Then I want to add that to a vector so I have a seri...

Recursive binary to decimal function without pow() or loops

I am doing a C course. I need to do a recursive XOR binary but I have some limitations. I can't use loop or any math.h functions, nor can I call another function from the XOR function. This is the function prototype: int binaryXor(int firstnumber[], int secondnumber[], int length); where firstnumber and secondnumber are arrays with t...

Python: Nested Loop

Consider this: >>> a = [("one","two"), ("bad","good")] >>> for i in a: ... for x in i: ... print x ... one two bad good How can I write this code, but using a syntax like: for i in a: print [x for x in i] Obviously, This does not work, it prints: ['one', 'two'] ['bad', 'good'] I want the same output. Can it be ...

how can i controll while loop into another while loop

Suppose I have a while loop like: $sql = mysql_query("SELECT * FROM tablename"); while($row = mysql_fetch_array($sql)){ $id = $row["id"]; $sql_2 = mysql_query("SELECT * FROM secondtable WHERE id != $id "); while($ro = mysql_fetch_array($sql_2)){ $id2 = $ro["id2"]; echo $id2; } } then if first query return 5 results i....

PHP adding leading 0 to range

How do I have it render leading 0's for 1-9 ? <?php foreach (range(1, 12) as $month): ?> <option value="<?=$month?>"><?=$month?></option> <?php endforeach?> ...

WCF Service call to multiple rows. How to architecture it?

Hi, Let's say I have a scenario where I have a Service that is responsible for retrieving the price of a single product given the ID and another Service that gives me the current stock position of it. It's okay when I'm looking only at one product, but what about a list page where I have 60 products? What should I do in this case? Call...

loop through HashMap Java jsp

Hello, the related Questions couldn't help me very much. How can i loop through a HashMap in jsp like this example: <% HashMap<String, String> countries = MainUtils.getCountries(l); %> <select name="ccountry" id="ccountry" > <% //HERE I NEED THE LOOP %> </select>*<br/> ...

Pushing data into array with JavaScript.

Hi, I'm relatively new to JavaScript and I've been having trouble pushing data into an array. I have two dynamic vars and I need the array to be formatted like: var array = [[-373597200000, 315.71], [-370918800000, 317.45], [-368326800000, 317.50]]; I already have a loop running for each iteration of the vars, I'm just not sure how I...

Excel VBA Select Case Loop Sub

In my excel file, I have a table setup with formulas. with Cells from Range("B2:B12"), Range ("D2:D12"), and etc every other row containing the answers to these formulas. for these cells (with the formula answers), I need to apply conditional formatting, but I have 7 conditions, so I've been using "select case" in VBA to change their i...

looping 1, 2 and 3 numbers

supposed to be I have 3 filenames file-00 file-01 file-02 I'm trying to replicate those files to file-03, file-04, file-05...file-98, file-99, file-100 based on the original files. So in bash I do #!/bin/bash x=0 y=1 z=2 for i in $(seq 0 100); do cp file-00 file-$((x=x+2)); cp file-01 file-$((y=y+3)); cp file-02 file=...

get all related tags?

this is very tricky. i´ve got a table with 2 columns thread_tag_map: thread_id and tag_name. thread_id tag_name 1 football 1 manchester 2 manchester 2 england 3 england 3 queen 4 queen 4 diana as you can see one thread can have multiple tags, and this gi...

C# Any way to repeat this process twice using a loop?

Hi, I'm in my first OOP class, and I was wondering if there was any way to use a loop (for, while, do-while) do loop through the process below twice, but store the results of the second iteration through the loop in two new variables, and then create a second ComplexNumber object using those variable values from the second iteration? ...

Line Break within echo in a while loop

Quick question, again, I'm sure this is ridiculously simple but I don't see what I'm doing wrong! while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "<a href=\"http://mysite.com/{$row['row1']}/{$row['row2']} \">{$row['row3']} </a>"; } This produces all my links to be stacked up one after the other. I want to order them in...

How do I loop through a date range?

I'm not even sure how to do this without using some horrible for loop/counter type solution. Here's the problem: I'm given two dates, a start date and an end date and on a specified interval I need to take some action. For example: for every date between 3/10/2009 on every third day until 3/26/2009 I need to create an entry in a List. ...

Technical non-terminating condition in a loop

Most of us know that a loop should not have a non-terminating condition. For example, this C# loop has a non-terminating condition: any even value of i. This is an obvious logic error. void CountByTwosStartingAt(byte i) { // If i is even, it never exceeds 254 for(; i < 255; i += 2) { Console.WriteLine(i); } } Sometime...

Python: Continuing to next iteration in outer loop

Hi, I wanted to know if there are any built-in ways to continue to next iteration in outer loop in python. For example, consider the code: for ii in range(200): for jj in range(200, 400): ...block0... if something: continue ...block1... I want this continue statement to exit the jj loop and goto ...

Illegal cyclic loop between nodes?

I am trying to loop through an XML file. As for the first loop everything works fine, but when the program enters the second loop it gives an error saying that TypeError: Error #1118: Illegal cyclical loop between nodes. at XML/http://adobe.com/AS3/2006/builtin::appendChild() Can anyone help me regarding this issue and suggest how to ...