Assume i have the following code, there are three for loop to do something. Would it run fast if i change the most outer for loop to while loop? thanks~~
int length = 200;
int test = 0;
int[] input = new int[10];
for(int i = 1; i <= length; i++) {
for (int j = 0; j <=length - i; j++) {
for (int k = 0; k < length - 1...
Hello good people,
I was using a foreach loop to go through a list of data to process (removing said data once processed--this was inside a lock). This method caused an ArgumentException now and then.
Catching it would have been expensive so I tried tracking down the issue but I couldn't figure it out.
I have since switched to a for l...
Suppose I want perform a simulation using the following function:
fn1 <- function(N) {
res <- c()
for (i in 1:N) {
x <- rnorm(2)
res <- c(res,x[2]-x[1])
}
res
}
For very large N, computation appears to hang. Are there better ways of doing this?
(Inspired by: https://stat.ethz.ch/pipermail/r-help/2008-February/155591....
Here is my code:
$today = date('Y-m-d');
for ($i = 1; $i <= 10; $i ++){
$var_b[$i] = date('Y-m-d', strtotime('-' . $i .' day', strtotime($today)));
$var2_b[$i]_name = date('d', strtotime($var_b[$i]));
Error message:
Parse error: syntax error, unexpected T_STRING in XXX\index.php on line XX
EDIT:
I put the curly brackets, the erro...
Hi, is it possible to do this? (here is my code)
for ($i = 0 ; $i <= 10 ; $i++){
for ($j = 10 ; $j >= 0 ; $j--){
echo "Var " . $i . " is " . $k . "<br>";
}
}
I want something like this:
var 0 is 10
var 1 is 9
var 2 is 8 ...
But my code is wrong, it gives a huge list. Php guru, help me !!
...
I have two arrays: $Forms and $formsShared.
<?php foreach ($Forms as $r): ?>
$("#shareform<?=$r['Form']['id'];?>").hide();
$(".Share<?=$r['Form']['id'];?>").click(function () {
$("#shareform<?=$r['Form']['id'];?>").toggle("show");
});
<?php endforeach; ?>
Currently, I have this hide and toggle function for each For...
Below is my code I am trying to get to work but I really have very little knowledge of array and foreach. So it doesn;t work correctly
I need to show a dropdown select form to the browser with the contents of the array
I also need to have the item selected if it is == to $mycountry
Lastly I would like to show the USA and UK at the top ...
Hello, I have a for loop as below which populates this data into an array.
I would like this to essentially populate 15 different array's, I have written some Pseudo code below. Is this achievable?
for (int y = 1; y < 16; y++) {
NSArray *array + y = item
}
...
Hi,
I am trying to find way to break / exit from FOR loop, if there are any error occured.
Below is content of batch file.
@echo on
set myfile=D:\sample.txt
FOR /F "tokens=1,2 delims=," %%i in (%myfile%) do call :process "%%i"
:process
set recfile=%1%
echo %recfile%
echo "Step in Test1"
echo %errorlevel%
pause;
exit /B 0
If %errorl...
In my example code below, is the counter = 0 really required, or is there a better, more Python, way to get access to a loop counter? I saw a few PEPs related to loop counters, but they were either deferred or rejected (PEP 212 and PEP 281).
This is a simplified example of my problem. In my real application this is done with graphics an...
Hi All,
I'm trying to write a small batch script that will delete files old files from a directory.
The first parameter is the directory for the script to look into, and the second is the number of files to preserve.
rem @ECHO OFF
rem %1 is the path in which to look for the files
rem %2 is the number of recent files to preserve
if [%...
This is a school problem I am working on for an intro Java class. The assignment is to write a program that generates an 8 x 8 matrix of randomly generated binary numbers and have the program check which, if any, columns are all 0's and if the major and minor diagonals are also comprised of zeroes. A major diagonal is the diagonal formed...
Here's what I got-
$awards_sql_1 = mysql_query('SELECT * FROM categories WHERE section_id = 1') or die(mysql_error());
$awards_rows_1 = mysql_num_rows($awards_sql_1);
$awards_sql_2 = mysql_query('SELECT * FROM categories WHERE section_id = 2') or die(mysql_error());
$awards_sql_3 = mysql_query('SELECT * FROM categories WHERE section...
There has to be a faster way of doing this.
There is a lot going on here, but it's fairly straightforward to unpack.
Here is the relevant python code (from scipy import *)
for i in arange(len(wav)):
result[i] = sum(laser_flux * exp(-(wav[i] - laser_wav)**2) )
There are a bunch of arrays.
result -- array of length (wav)
laser_f...
Ok. so I'm working on an app that retrieves items from a db and builds a gallery. I've done this a ton of times, and it should be simple.
I'm running into problems, because in this gallery, I get results from a db that includes both image files, and other files. Let's just say I can't change anything but the flash, so I need to detect i...
Hi All,
This is my config.ini file
options affecting ndbd processes on all data nodes:
[ndbd default]
NoOfReplicas=1 # Number of replicas
DataMemory=80M # How much memory to allocate for data storage
IndexMemory=18M # How much memory to allocate for index storage
# For DataMemory and IndexMemory, we have use...
I would like to increment 2 variables in a for-loop condition instead of one.
So something like:
for(int i = 0, i != 5; ++i and ++j) do_something(i,j);
What is the syntax for this?
...
Realizing that loops are usually not ideal in R, sometimes they are necessary.
When writing large loops, doesn't
for (i in 1:large_number)
waste memory, since a vector of size large_number must be created?
Would this make while loops the best choice for large, necessary loops?
...
Is it different than C or C#?
...
Hello everyone,
Just a quick question.
I have a loop that looks like this:
for (int i = 0; i < dim * dim; i++)
Is the condition in a for loop re-evaluated on every loop?
If so, would it be more efficient to do something like this?:
int dimSquare = dim * dim;
for (int i = 0; i < dimSquare; i++)
Thanks
-Faken
...