loops

Parse PHP String Based On Number of Characters

Hello all, I'm starting to work on a small script that takes a string, counts the number of characters, then, based on the number of characters, splits/breaks the string apart and sends/emails 110 characters at a time. What would be the proper logic/PHP to use to: 1) Count the number of characters in the string 2) Preface each messag...

C++ creating and collecting structs in a loop

I want to create a struct from data harvested by line from a file. Each line necessitates a new struct, and the lines are accessed in a while loop. In C# I did this by creating anonymous structs and adding them to a list of structs. C++ would seem not to allow anonymous structs. I tried naming them with an incrementing variable, but this...

C++ How to loop through a list of structs and access their properties

I know I can loop through a list of strings like this: list<string>::iterator Iterator; for(Iterator = AllData.begin(); Iterator != AllData.end(); Iterator++) { cout << "\t" + *Iterator + "\n"; } but how can I do something like this? list<CollectedData>::iterator Iterator; for(Iterator = AllData.begin(); Iterator != ...

How to replace slide effect to fade out/fade in effect on this slideshow?

Hi guys! I need replace slide effect to fade-out/fade-in effect on the prev and next slide functions: function animate(dir,clicked){ u = true; switch(dir){ case 'next': t = t+1; m = (-(t*w-w)); current(t); if(o.autoHeight){autoHeight(t);} if(s<3){ ...

Javascript Canvas Element - Array Of Images

I'm just learning JS, trying to do things without jQuery, and I want to make something similar to this however I want to use an array of images instead of just the one. My image array is formed like this var image_array = new Array() image_array[0] = "image1.jpg" image_array[1] = "image2.jpg" And the canvas element is written like t...

Java For-Each Loop : Sort order

Does a java for-each loop guarantee that the elements will be presented in order if invoked on a list? In my tests it does seem to, but I can't seem to find this explicitly mentioned in any documentation List<Integer> myList;// [1,2,3,4] for (Integer i : myList) { System.out.println(i.intValue()); } #output 1,2,3,4 ...

Any reason to replace while(condition) with for(;condition;) in C++?

Looks like while( condition ) { //do stuff } is completely equivalent to for( ; condition; ) { //do stuff } Is there any reason to use the latter instead of the former? ...

jQuery cross fading two images on a loop!

Hi, I am having trouble working out how to get a simple fade in fade out loop to work. I am pretty new to jQuery as you can maybe tell. I have had a go at it but now it’s taking too long to work out so I thought I would ask for some help. What I want to do: I have two Images, id's #img1 and #img2. I want image 1 to fadeIn then wait fo...

Resources for (Manual and Automatic) Loop Vectorization

I see some resources for gcc, but not for Visual Studio. Anyone have a treasure trove of references, examples and tricks? ...

Is there a systematic way to convert R code with loops to vectorized code?

Most looping code looks like this retVal=NULL for i { for j { result <- *some function of vector[i] and vector[j]* retVal = rbind(retVal,result) } } Since this is so common, is there a systematic way of translating this idiom? Can this be extended to most loops? ...

PHP round numbers, add decimal numbers

I'm using a simple loop to echo back some numbers <?php $inc = 0.25; $start = 0.25; $stop = 5.00; ?> <?php while($start != ($stop + $inc)){ ?> <option><?php echo $start ?></option> <?php $start = $start + $inc; ?> <?php } ?> However 5.00 appears as 5 and 4.50 appears as 4.5 How would i get this script to display 5.00, 4.00, 3.00, 3...

JQuery loop through 2-dimensional array of elements

Hello, I need to loop through a set of 2-dimensional array of hidden input fields and display matching values next to each other. Example of hidden fields: <input type="hidden" name="list[en][1]" class="list" value="Keyword"> <input type="hidden" name="list_desc[en][1]" class="listdesc" value="Keyword description"> ...

use of goto versus runtime code evaluation

Recently for a programming class, we were given the assignment to write a program in any language that, given n, will produce all the possible derangements for an array p of size n such that p[i] != i for all i: 0 <= i < n. We had to use iterators, e.g. yield. Example: n=3, [0, 1, 2] is not a derangement, but [2, 0, 1] is as well as [...

javascript closure immediate evaluation

Hi, Consider the following Javascript code: var a = []; var f = function() { for (var i = 0; i < 3; i++) { a.push(function(){alert(i)}); } for (var j = 0; j < 3; j++) { a[j](); } }; The alerts print out '3' all three times. I want a different behaviour - in each iteration of the loop generate a funct...

How to improve speed of this readline loop in python ?

Hi all, i'm importing several parts of a Databasedump in text Format into MySQL, the problem is that before the interesting Data there is very much non-interesting stuff infront. I wrote this loop to get to the needed data: def readloop(DBFILE): txtdb=open(DBFILE, 'r') sline = "" # loop till 1st "customernum:" is found while slin...

Javascript complex array "element reduction" - building an HTML table based on array elements

I have a project that requires the following. Four arrays will be declared in the code as such: var ROW1 = ['module1']; var ROW2 = ['module2', 'module3']; var ROW3 = ['module4', 'module5', 'module6']; var ROW4 = ['module7', 'module8']; Each element of these arrays represents a module in a configurable HTML widget. Based on what eleme...

How to break out of a loop from inside a switch?

Hi, I'm writing some code that looks like this: while(true) { switch(msg->state) { case MSGTYPE: // ... break; // ... more stuff ... case DONE: break; // **HERE, I want to break out of the loop itself** } } Is there any direct way to do that? I know I can use a flag, and break from the loop by pu...

How to loop through WPF StackPanel static Items?

Probably very easy but I am having trouble to figure this out (also Google doesn't seem to help much). How can I loop through the statically declared elements (no databinding - elements are declared in the xaml) of a StackPanel? Any help appreciated! ...

Launching a thread from a loop and passing Loop ID

I just started playing around with threading today and I ran into something that I dont understand. public void Main() { int maxValue = 5; for (int ID = 0; ID < maxValue; ID++) { temp(ID); } } public void temp(int i) { MessageBox.Show(i.ToString()); } As basic as it gets which works fine, but when I try t...

Loop with 8 times

How I do a Loop with 8 times with this entire function? Only changing the var n $(document).ready(function(){ var n=2; $forms = $('#form'+n); $('#toogle'+n).hide(); $('#hide'+n).hide(); $('a').bind('click', function(){ switch(this.id){ case 'c'+n: $('#change'+n).hide(); $('#...