for-loop

Loop in C help!

My friends tell me that a special loop exists that isn't a 'while' loop or a 'do while' loop. Does anyone know what it's called and the correct syntax for it's use? ...

Make a string null in a single line

To make a string a null string i wrote this: #include<stdio.h> #include<conio.h> #include<string.h> int main() { char str[15]="fahad uddin"; strlen(str); puts(str); for(int i=0;str[i]!='\0';i++) strcpy(&str[i],"\0") ; puts(str); getch(); return 0; } Before this i tried: #include<stdio.h> #include<c...

For loop condition to stop at 0 when using unsigned integers?

I have a loop that has to go from N to 0 (inclusively). My i variable is of type size_t which is usually unsigned. I am currently using the following code: for (size_t i = N; i != (size_t) -1; --i) { ... } Is that correct? Is there a better way to handle the condition? Thanks, Vincent. ...

Parse error: parse error, expecting PHP For Loop

. function is_valid_isbn($isbn) { $isbn_length = strlen($isbn); $isbn_sum = 0; echo "this is the length :"; echo $isbn_length; for($i=0; $i < $isbn_length; $i++) { $total += (substr($isbn, $i, 1) * (11-($i+1))); } return true; } When i run this function i am getting following error can some one help me where is the e...

find value of forloop at which event occurred Python

hey guys, this is very confusing... i am trying to find the minimum of an array by: for xpre in range(100): #used pre because I am using vapor pressures with some x molarity xvalue=xarray[xpre] for ppre in range(100): #same as xpre but vapor pressures for pure water, p pvalue=parray[p] d=math...

Am i doing this iteration right in javascript?

Consider the two implementations below, data.addRows([ ['2004', 1000], ['2005', 1170], ['2006', 660], ['2007', 1030] ]); The above works (ie) it gets me what i want. and my implementation is, for (var i = 0; i < 10; i++) { data.addRows['row'+i,i]; } Is this a valid for loop or what am i doing wrong? I am usin...

PHP: Make the loop and variable variables into a function

Hi, How can I make the code below into a function? # split the string by string on boundaries formed by the string delimiter will split the value into an array like the example below, # Array # ( # [0] => pg_cat_id=1 # [1] => tmp_id=4 # [2] => parent_id=2 # ) $array_parent = explode("&", $string); //print_r($array_parent); ...

Contents of string change when exiting loop

I have a simple function, that checks if the strings given match a certain condition, then generate a 3rd string based on the 2 ones received as arguments. The 3rd string is fine but when I return it it suddenly turn into "\n". string sReturn = ""; if (sText.size() != sPassword.size()) { //Checks to see if the texts match a conditi...

What is the difference between infinite while loops and for loops?

I see the different conventions used in many books I had read, where you would create infinite loops with either loop structure such as: while() foo(); for(;;) foo(); But really, what are the differences I should know about? which one is better? ...

Insert 52 weeks for each year in MySQL (PHP script)

Hi, I want in a table called week_year with following schema: Week_year = {id, week, year} To insert the weeks for each year, such that, for 2001 there is week 1, week 2, week 3, … , week 52, and then start over for year 2002 up until the year 2009. I’ve tried different PHP scripts but can’t seem to be getting it right. I’ve tried ...

Java: Initialize multiple variables in for loop init?

I want to have two loop variables of different types. Is there any way to make this work? @Override public T get(int index) throws IndexOutOfBoundsException { // syntax error on first 'int' for (Node<T> current = first, int currentIndex; current != null; current = current.next, currentIndex++) { if (currentIndex...

Accessing later index in array using enumerate(array) Python

hey guys, how would you access an array from array[n] in an array of 100 floats in this for loop (i need the enumerate): for index,value in enumerate(array): #do stuff with array[n] n=n+1 im trying to make it so that it operates in a smaller and smaller space each iteration.. thanks ...

Possible to make this code valid/speed up?

I have an enrollment form which takes consumer information, stores it in session, passes from page to page then stores in a database when finished. Originally the table simply listed fields for up to 16 persons but after reading into relational databases, found this was foolish. I have since created a table named "members" and "manager...

Jquery - How to alternate an :Odd :Even pattern every 4 <Divs>?

Hi I'm trying to make a pattern in a layout (see attachment for visualisation) The problem is that using :odd :even doesnt work. I've tried to make it work by using "for loops", and if statements, but obviously jquery doesn't do this stuff in that way. Or maybe i'm supposed to do it outside the document ready statement? I tired that to...

Objective-C Yield/Wait for function to return?

Hello! In objective c how would you get a function to pause until another one returns? Thanks! Christian Stewart ...

Reading empty values in "for" command in a windows batch file

I have a question with the "for" batch command in windows. I have a file called keys.txt which contains this line.. key,value,x86,windows7 I want to parse this line and store the 4 comma seperated variables in 4 variables. I accomplish that by the following windows batch script. for /F "tokens=1,2,3,4* delims=," %%i in (keys.tx...

how to printf a loop result?

How to printf results from a loop? For example if i have this something simple like this: k[0]=2; k[1]=3; k[2]=4; for (i = 0 ; i <= 2 ; i++) { x[i]=5*k[i]; } How do I print out the results for x[0],x[1],x[2] without having to keep repeating the array in printf? As in printf("%d %d %d\n",x[0],x[1],x[2]); I dont really want ...

why does this for loop returns null?

<? for ($i=0; $i<=9; $i++) { $b=urlencode($cl[1][$i]); $ara = array("http://anonymouse.org/cgi-bin/anon-www.cgi/", "http%3A%2F%2Fanonymouse.org%2Fcgi-bin%2Fanon-www.cgi%2F"); $degis = array("", ""); $t = str_replace($ara, $degis, $b); $c="$t"; $base64=base64_encode($t); $y=urldecode($t); $u=base64_...

EXC_BAD_ACCESS in for loop

In this code, in the second for loop, i get an EXC_BAD_ACCESS if I use an identifier other than i and j. if (UIDeviceOrientationIsPortrait(deviceOrientation)){ numRows = 4; numCols = 3; }else { numRows = 6; numCols = 1; } for (int row = 0; row < numRows; row++){ for (int col = 0; col < numCols; col++) { ...

How to reverse the order in a FOR loop

I've a simple FOR statement like this: var num = 10, reverse = false; for(i=0;i<num;i++){ console.log(i); } when reverse is false I want it to return something like [0,1,2,3,4,5,6,7,8,9] but, when reverse is true, it should return [9,8,7,6,5,4,3,2,1,0] Which is the most efficient way to get this result, without checking eve...