for-loop

Java 2dim table for-iteration

I'm writing a 'Sudoku' program, and I need to write a method to check whether a number, the user wants to insert in a certain cell is already contained by the row, column or region. My code looks like this(I'm only checking the row for the number at this point, setNumber returns a boolean value indicating whether the number can be insert...

Help with for /f batch file

heres my code: start /realtime /b /wait .\jampDed.exe for /f "tokens=1-5 delims=:" %%d in ("%time%") do rename .\CIA_Secure_Host2\qconsole.log %%d-%%e-%%f start .\Serv.bat cmd this batch is supposed to run the program in a window, and when it quits, is supposed to rename the file qconsole.log to the current time, and then relaunch the...

Iteration through arrays in arrays PHP

Hello How can i itarate this array array(2) { [0]=> array(1) { [0]=> array(14) { [0]=> string(17) "ratosk8@censored" [1]=> string(23) "alokkumar.censored" [2]=> string(24) "uuleticialima1@censored" [3]=> string(23) "camera.clicks@censored" [4]=> string(24) "billtha...

Output results of a task in a FOR loop with added variables for logging

G'day all, Trying to output the results of the task I'm running in a FOR loop with additional data. In this case, I'm using the FOR loop to read in server names from a text file to setup a scheduled job. I would like to capture the results on each loop and output to a log file but need to insert additional information such as server nam...

Need help geocoding town names to their coordinates in a loop

Hi, Ive read similar posts, but still didnt find a solution for myself. Basically I have an array with countries+towns in PHP and I need to show them on the map with markers. Here is my code: function showAddress(markers) { var address = "<?php echo $Fcity[$j], " , ", $Fcountry[$j]?>"; if (geocoder) { geocoder.getLatLng(address, f...

VB6 Type Mismatch in For loop condition

I have been trying to find out why in the following code, the third time through the loop I am getting a Error type 13 Mismatch when the line "For lCount = 0 To maxCount" is being evaluated. I had originally thought the problem was in getting the value from the vArray, but testing shows it to be triggered by the "For" line. I haven't a c...

One Line 'If' or 'For'...

Every so often on here I see someone's code and what looks to be a 'one-liner', that being a one line statement that performs in the standard way a traditional 'if' statement or 'for' loop works. I've googled around and can't really find what kind of ones you can perform? Can anyone advise and preferably give some examples? For example...

iterating over map and array simultaneously in a for loop

I am having some trouble creating a for loop within a constructor to iterate over a map and an array at the same time. Here, it is indicated that this cannot be done with an enhanced for loop. I have something like this, which raises a compiler error. Basically, the class has a Map which I want to populate via the constructor which take...

PHP str_replace with for loop from array

Ok I have a str_replace and what I want to do, is take values from an array, and take the next piece to replace the word "dog" with. So basically I want the $string to read: "The duck ate the cat and the pig ate the chimp" <?php $string = 'The dog ate the cat and the dog ate the chimp'; $array = array('duck','pig'); for($i=0;$i<count($...

Weird acting loop in C#

Note: I added actual code snippets. Just scroll to end. // files is created by a OpenFileDialog. public void Function(String[] files, ...) { for(int i; i<files.Length; i++) { WriteLine("File " + i + "/" + files.Length + " being processed."); //... processing for a long time and printing information to console ... }...

How does the Python's range function work?

Hi,all,I am not really understand for loop in the following,can anyone give some tips?thanks in advance for i in range(5): print i then it gives 0,1,2,3,4 is that python assign 0,1,2,3,4 to i at the same time? however if i wrote: for i in range(5): a=i+1 then I call a, it gives 5 only, but if i add ''print a'' it gives ...

as2 simple for loop not populating textbox.

I have got an xml file that brings text into a flash movie in the form of an array, I need to population some textboxes and want to do this using a for loop. My loop look like this: for(var i=0; i<first_array.length; i++){ this.animation1.text_mc[i].txt[i].htmlText = first_array[i]; } if i hardcode the path, without [i], it...

PHP - Foreach loops and ressources

I'm using a foreach loop to process a large set of items, unfortunately it's using alot of memory. (probably because It's doing a copy of the array). Apparently there is a way to save some memory with the following code: $items = &$array; Isn't it better to use for loops instead? And is there a way to destroy each item as soon as they ...

Should I subtract 1 from the upper bound of my "for" loops?

I'm having a bit of trouble figuring out what's going wrong with this function. I'm not sure if I should be using -1 or not anymore, and no matter how I try to arrange the code it seems to return nil even when it shouldn't. Could someone with fresh eyes take a look? Also, I'm not sure my result := nil is in the proper place. function TF...

For loop in while loop

Hi, can I put a for loop in while loop? For example: while($end = 1) { for ($i = 0; $i < count($match); $i++) { $mathcas = $match[$i][1]; } } Thanks. :) ...

How to save values with loop

Hey guys, I am trying to add the returned value from the test() function into a the variable result, but += does not seem to work. I get the error "invalid variable initialization". I also tried replacing i++ to i+= which didnt work either. Maybe I'm totally wrong and should use a while loop instead? I'm quite lost.. I want 'result' to ...

Memory Leak when using for(object in array) with iPhone SDK

Hey Everyone, I am running into some serious memory leaks in one of my applications I am building. I have a UINavigatonController that is inside a UITabBarview. Inside the NavView is a MKMap view. When you click an accessory button on a callout a detail view is loaded. In that detail view I am trying to populate a table from a plist usi...

Javascript - How should I calculate the result use for loop?

Suppose a carpark charges a $2 minimum fee to park for up to 3 hours, then the carpark charges an additional $0.5 per hour for each hour. For example, park for 5 hours charge $2+$0.5+$0.5=$3 How should I calculate the fee use for loop? ...

Change a Recursive function that has a for loop in it into an iterative function?

So I have this function that I'm trying to convert from a recursive algorithm to an iterative algorithm. I'm not even sure if I have the right subproblems but this seems to determined what I need in the correct way, but recursion can't be used you need to use dynamic programming so I need to change it to iterative bottom up or top down ...

Are loops with and without parenthesis handled differently in C?

I was stepping through some C/CUDA code in the debugger, something like: for(uint i = threadIdx.x; i < 8379; i+=256) sum += d_PartialHistograms[blockIdx.x + i * HISTOGRAM64_BIN_COUNT]; And I was utterly confused because the debugger was passing by it in one step, although the output was correct. I realised that when I put curly ...