FAQ Database Discussion Community


Methods within my while Loop not working

python,loops
I'm making a simple script that looks to see if my favourite YouTuber Casey Neistat has uploaded a new video. I want the script to loop over and over so see if there is a new video or not. However, whenever I run the program it continually says that there...

wrong results from simple java method [duplicate]

java,arrays,loops
This question already has an answer here: Java - simple division in Java ---> bug/feature? [duplicate] 4 answers I'm trying to write a program that asks for the size of an array of integers, the values of the array, and then finds the average of the positive integers and...

Nested foreach loop in a While loop can make the condition for the while loop go over?

php,loops,foreach,while-loop
Here is a little background on what I am trying to create. I am creating a function called getNextBilling($dateStart,$dateCount = 20) You give it a period length which is the days you want someone to be billed $test->period = '2,5,15'; it takes a starting date which I have assigned on...

PHP: How to push Select results to multi-dimensional array (partially working)

php,arrays,loops,select,multidimensional-array
I am new to PHP and hope someone can help me with this. I have a Select query that returns (among others) the values from two columns in a db table, "ID" and "en". When getting the results from the Select I would like to store both these values for...

How to innerHTML a function with array as parameter?

javascript,arrays,loops,foreach,innerhtml
I am learning about looping thorugh arrays - I want to pass the result of an if else statement in the forEach function (inside another function with array as parameter) to HTML using innerHTML (does not have to be innerHTML if you know better methods I do not mind). It...

How do I use the Find function with a variable term, for example Run1, Run2, RunX

vba,excel-vba,loops,variables
Cells.Find(What:="Run:1", After:=Cells(1, 1), _ LookIn:=xlValues, LookAt:=xlPart, _ SearchOrder:=xlByColumns, SearchDirection:=xlNext, _ MatchCase:=False, SearchFormat:=False) This is the code that I want to use, but I would like to loop it to find Run:1, Run:2, Run:3... Etc..., Is there a way to add a variable in a reference to find "Run:X"?...

How does a while loop inside a for loop work?

java,loops
Sorry for the basic question. But does the code finish executing the inner while loop and then update the count in the outer for loop? or does it perform each variable update in an alternating fashion? example: int j= 1; for(int i=0; i< 5; i++) { while(i <3) { j++;...

How can I iterate through nested HTML lists without returning the “youngest” children?

javascript,jquery,html,list,loops
Fiddle: https://jsfiddle.net/zayjeLrk/12/ I want to iterate through an HTML nested list that is 3-layers deep. <ul> <li>animals <ul> <li>birds <ul> <li>crow</li> <li>parrot</li> </ul> </li> <li>reptiles</li> </ul> </li> <li>plants</li> <li>bugs</li> </ul> I want it to iterate through the list so that it returns the elements in this order (note, this isn't...

How can i make a jQuery animation loop on infinite, after it finish?

jquery,loops,animation
I have a jQuery animation, i have a flying monkey that has to rotate from left to right and from right to left, is working fine but i have to make the monkey loop. Right now i have improvised, i have made several divs into each other that rotate after...

while loop is not breaking even if the condition is satisfied

c,loops,while-loop,iteration
I have created a program to print armstrong number, but the inner while loop is not breaking, it should break when the value is 0, but it is going into continuous loop. Can anyone tell me what's wrong in my program. Is this the correct behaviour of compiler. #include<stdio.h> int...

Check for new files in a loop - java

java,loops
I have a program that needs to read files. I need to check every 10 seconds if there is new files. To do that, I've made this : ArrayList<File>oldFiles = new ArrayList<File>(); ArrayList<File>files=new ArrayList<File>(); while(isFinished != true){ files=listFilesForFolder(folder); if(oldFiles.size() != files.size()){ System.out.println("Here is when a new file(s) is(are) in the...

how to find a specific objet in a liste of object (other way than a loop)

php,loops,object
I would like to know if it is possible to easily retrieve an object from a list through its id (or any other way). So far to do so I have to do a loop and test each object to see if it is the correct one. EXEMPLE Here as...

Run external R script n times, with different input paramters, and save outputs in a data frame

r,loops
my question ties to the following problem: Run external R script n times and save outputs in a data frame The difference is, that I dont generate different results by randomization functions but would like to use every time a different set of input variables (e.g. run the chunk of...

How to dynamically name my object params in this lodash loop?

javascript,loops,for-loop,lodash
https://lodash.com/docs#find var params = {}; _.forEach(n.tags, function(n, index) { console.log(index); index++ // For each tag, create new param.term1, term2, term3 etc... params.term[index] = _.result(_.find(n.tags, function(term_id) { return term_id; }), 'term_id'); }); The _.forEach will loop over n.tags (which contains up to 3 tags). I iterate the index++ by 1 so...

Object Variable or With Block Variable Not set in loop using find function

vba,excel-vba,loops,object,find
Sub Main() Dim FName As Variant, R As Long, DirLoc As String, i As Integer R = 1 i = 1 DirLoc = ThisWorkbook.Path & "\" 'location of files FName = Dir(DirLoc & "*.csv") Do While FName <> "" ImportCsvFile DirLoc & FName, ActiveSheet.Cells(R, 1) R = ActiveSheet.UsedRange.Rows.Count + 1...

Interface Controls for DoEvent in Excel

excel,vba,excel-vba,loops,doevents
I have a macro to loop through a range and return emails to .Display based on the DoEvents element within my module. I iterate that: row_number = 1 'And Do DoEvents row_number = row_number +1 'Then a bunch of formatting requirements Loop Until row_number = 'some value I am wondering...

Incrementing an integer and initialisation placement having a weird effect?

c,loops,int
I have written the following 'Hangman game'-program in C (was written quick and dirty so don't mind the code too much): #include <stdio.h> int main() { char word[] = "cat"; int amountGuessesAllowed = 5; size_t size = sizeof(word)-1; // -1 to exclude the '\0' char guessedWord[size]; for (int i=0; i<size;...

matlab Create growing matrix with for loop that grows by 3 per loop

matlab,loops,for-loop,matrix
So I have written this: HSRXdistpR = squeeze(comDatape_m1(2,7,1,:,isubj)); HSRXdistpL = squeeze(comDatape_m1(2,4,1,:,isubj)); TocomXdistp = squeeze(comDatape_m1(2,10,1,:,isubj)); for i = 1:2; HSRXp = NaN(8,3*i); HSRXp(:,i*3) = [HSRXdistpR(:,i) HSRXdistpL(:,i) TocomXdistp(:,i)]; end In the first part I am just selecting data from a 5-D matrix, nothing special. All that's important here is that it creates...

Matlab: Writing to a file

arrays,matlab,loops,math,for-loop
I want to store mean_2....mean_8, std_2....std_8, and coVariance as separate columns in a file. Help Please? This Code calculates IntervalFeatures of Erp signal with 256 time frames and plots them Datapoints are store in A ___________HowTheCodeWorks________________________________________________ each 1x4 sliding sub-matrix is made a column for eg:- if A is...

How to iterate through a table in its exact order?

loops,for-loop,lua,order
If i try to output this table, they are looped through in the false order: local letters = {DIN1="hi", AIN1= "my", AIN2 ="name", DIN2="is"} for name, value in pairs(letters) do print(name,value) end Expected Output: DIN1 hi AIN1 my AIN2 name DIN2 is Output: AIN1 my DIN2 is DIN1 hi AIN2...

Plotting multiple graphs in one page using loop

r,loops,plot
I am trying to plot multiple graphs on the same page. It works fine when I write the code one by one like this: old.par <- par(mfrow = c(3,4)) plot(na.omit(AUS.Yield), xlab = "Date", ylab = "log_return", main = "AUS.Yield") plot(na.omit(BRA.Yield), xlab = "Date", ylab = "log_return", main = "BRA.Yield") plot(na.omit(CAN.Yield),...

Python: TypeError: list indices must be integers, not list

python,list,loops,indices
I've got two lists of coordinates, they look like this: list_kp2_ok: [[1185.60009765625, 933.6000366210938], [1310.4000244140625, 828.0000610351562], [1067.0, 979.0], [1310.0, 828.0], [1423.2000732421875, 814.800048828125], [1306.0, 828.0], [3634.0, 605.0], [1308.0960693359375, 827.7120971679688], [1422.7200927734375, 815.0400390625], [1185.1199951171875, 933.1200561523438], [1186.56005859375, 923.0400390625], [1306.3681640625, 829.4401245117188], [1194.393798828125, 839.80810546875], [1187.1361083984375, 922.7520751953125],...

How do I write a loop to read text file and insert it to the database

sql-server,loops,powershell
I'm writing a powershell script to load text files from a specific folder into SQL server database, I have manage to do so but only one file by one file. I want the program to do this automatically once the user inputs the path and the file extension. For example:...

Trying to output a list of lists from a loop in r

r,loops
I am trying to do something that I am sure should be quite simple: I am trying to make a function which turns a list of number pairs (pairedList) and a vector (botList) into a series of vectors (one for each pair) of length(botlist) where the numbers in those vectors...

Python - Using a created list as a parameter

python,list,loops,if-statement,compare
When I run my code it tells me: Type Error: unorderable types: str() < float(). I can't figure out why it won't let me compare these two numbers. The list I am using is defined, and the numbers in it have been redefined as floats, so I'm not sure what...

IllegalStateException: Iterator already obtained [duplicate]

java,file,loops,path
This question already has an answer here: java.lang.IllegalStateException: Iterator already obtained 1 answer so I wrote a little Java program to test a little stack language I made vie various test file, but for some reason it won't work. Here is the code: import org.apache.commons.io.FilenameUtils; import java.io.IOException; import java.nio.file.*;...

How can I reset my program? (without using goto) [closed]

c++,loops,reset,goto
Basically I have finished programming a little times tables quiz for my little brother.I am very new to programming and I have no idea how to reset my program back to the start. Can anyone shed some light on this? #include <iostream> #include <string> #include <fstream> using namespace std; int...

How to use _lodash to retrieve value from Objects in Array?

javascript,arrays,loops,lodash
Here is my Array containing Objects, each Object has a ticker value: [Object] 0: Object $$hashKey: "object:130" tags: Array[1] ticker: Object company: "Alcoa Inc." direction: "negative" percent: -3.89 price: 14.59 selected: true ticker: "AA" There could be several objects, how would one use the _lodash library to pull out the...

Appending a data frame with for if and else statements or how do put print in dataframe

r,loops,data.frame,append
How do I put what I printed in a dataframe with a for loop and if else statements? Basically, this code: list<-c("10","20","5") for (j in 1:3){ if (list[j] < 8) print("Greater") else print("Less") }) #[1] "Less" #[1] "Less" #[1] "Greater" Or should it be something more like this? f3 <-...

Add mouseListener to Labels in Array Loop

java,loops,mouselistener
I want to add mouseListener to all labels in the array. Every label should show an other card of the layout. If I use below code, all labels show card6. What is wrong? sorry this is correct code.. panList = new JPanel(); panList.setBounds(0, 0, 206, 517); panList.setLayout(null); cs.add(panList); CreateCards(); int...

Comparing two values in the same row and change if needed

php,mysql,loops
Im trying to compare two values in the same record and if $minvoorraad > $voorraad , set $voorraad = $minvooraad. Database(cropped picture): This is what i have now but it changes all numbers to same <?php session_start(); include 'connect.php'; $sql = "SELECT Minvoorraad, Voorraad FROM product"; $query = mysqli_query($con, $sql);...

Matlab: Looping through an array

matlab,loops,for-loop,while-loop,do-while
This is my one dimensional array A. containing 10 numbers A = [-8.92100000000000 10.6100000000000 1.33300000000000 ... -2.57400000000000 -4.52700000000000 9.63300000000000 ... 4.26200000000000 16.9580000000000 8.16900000000000 4.75100000000000]; I want the loop to go through like this; (calculating mean interval wise) - Interval length of 2,4,8 (a(1)+a(2))/2 - value stored in one block of...

how to make a loop and if statement that loops through a different groups of radio buttons (javascript)

html,loops,twitter-bootstrap-3,radio-button
**HTML** <li class="option"> <input type="radio" name="Answer1" value="A">A</input><br> <input type="radio" name="Answer1" value="B">B</input><br> <input type="radio" name="Answer1" value="C">C</input><br> <input type="radio" name="Answer1" value="D">D</input><br> </li> <li class="option"> <input type="radio" name="Answer2" value="A">A</input><br> <input type="radio" name="Answer2"...

Javascript: Forloop Difference between i++ and (i+1)

javascript,loops,for-loop
I was building a javascript for loop and I want to compare the value of an array to the next value in the array. If both values are not equal, I want to return true, otherwise I want to return false. In the code below I pass the string "aba",...

How to print iterations per second?

python,performance,loops,cmd,progress
I have a small Python script which sends POST requests to a server and gets their response. It iterates 10000 times, and I managed to print the current progress in command prompt using: code=current_requestnumber print('{0}/{1}'.format(str(code),"10000"),end="\r") at the end of each loop. Because this involves interaction with a webserver, I would...

Nil errors in creating a hash in Ruby on Rails

ruby-on-rails,arrays,ruby,loops,ruby-on-rails-4
I'm running into several syntax and nil issues when trying to create this hash idea_benefit_count. @idea = @domain.ideas @idea_evaluations = Array.new() @idea.each do |idea| @idea_evaluations << idea.evaluations end @idea_benefit = [] if [email protected]_evaluations.nil? @idea_evaluations.each do |eval| @idea_benefit << eval.benefit end @idea_benefit_count = Hash.new(0) @idea_benefit.flatten.each { |idea_benefit| @idea_benefit_count[idea_benefit] += 1 }...

Difference between two similar functions, why is one working and the other not

javascript,jquery,loops,vue.js
I have two functions, one working, the other not. They are equal, except that the one is looping through a variable, in which the global object of the scope is saved (hope this makes sense), and the other tries to loop through the text directly, but fails, because it throws...

Problems retrieving nested data from json

javascript,html,json,loops,nesting
I am working on a small project and i made the following json data -> http://www.smartbustracking.be/json/data.json. The following below code loops through my json data. I can successfully read the "busuur" but not the nesting of bussen. Am i writing the code wrong of is my syntax not correct <script...

Infinite loop with fread

c,arrays,loops,malloc,fread
I'm trying to allocate an array 64 bytes in size and then loop over the array indexes to put a read a byte each from the inputfile. but when I don't malloc() the array indexes, the loop stays in index0 (so each time it loops it replaces the content in...

C++ Same name local variables keeping values between loops [closed]

c++,loops,for-loop,local-variables
I have the following 2 loops in my C++ code: for (int hcount = 0; hcount < height; hcount++) { for (count = 0; count < width; count++) { cout << character; } cout << endl; } cout << endl; for (int hcount = 0; hcount < height; hcount++); {...

C++ - back to start of loop without checking the condition

c++,perl,loops,redo
Programming on perl, we can use a smart function named 'redo' - we can go back to the start of the loop, without looking at the condition. It's useful when, for example, we create a table in which we must to set a expected values/characters (e.g. "a-b-c", nothing else). I...

Counter not working after jumps - assembly language

loops,assembly,counter,increment
For some reason, when i switch to mouse input switch back to keyboard input for my program, increasing and decreasing the counter has no effect. It works perfectly in the first loop where we input characters. Here is the program guys, any advice? look at whatspeed jump for reference after...

Iterate through a specific directory tree and store all the .ttf files into an array in PHP

php,loops,iterator,directory,iteration
Lets say I have a lot of files, some of those are in these paths: root/fonts/folder1/font1.ttf root/fonts/folder1/font2.ttf root/fonts/folder2/font1.ttf root/fonts/folder2/font2.ttf root/scripts/file.php Remember that there are also other types of files in those folders. How can my "/scripts/file.php" iterate through the "../fonts/" directory tree and store all the TrueType font (.ttf) files...

for loop - checking if numbers in array move more up or down

java,arrays,loops
I am using a for loop to check whether the array i enter in as a parameter has more ups or downs in terms of integers. I am not sure why but my compiler is throwing an index out of bounds exception. Would be nice if someone can just point...

For-Each Loop Alternative - Clarification

java,loops,foreach,iterator
I am working through lessons in Java, and have not been able to completely understand what is going on in the following lesson. Purpose: The purpose of this lesson is to explain how a for-each loop works by creating an alternative that simulates how the for-each loop would work. In...

GPA Calculator in C

loops,for-loop,do-while
I'm trying to get this code to calculate a class's average GPA. The problem I'm having is that I seem to have made a mistake in my do...while code, because, when I run it, it constantly loops back to asking me to input another GPA, rather than asking if I...

performance issues executing list of stored procedures

c#,multithreading,performance,loops
I'm having some performance issues when starting my windows service, the first round my lstSps is long (about 130 stored procedures). Is there anyway to speed this up (except for speeding the stored procedures up)? When the foreach is over and goes over to the second round it goes faster,...

Matching key/value pairs in two dictionaries and creating a third one

python,loops,dictionary
I have read two files from which I created dictionaries with IDs and their corresponding sequences as keys and values, respectively. I am trying to find the key/value pairs that exist in both dictionaries and to create a new one containing only these matching ones. Each dictionary has a couple...

How to iterate multi dimensional array and calculate sum for each row in php?

php,arrays,loops,foreach,dimensional
i have this array which i retrieved data from my database and put it in an array : $query = "select * from caseunder"; $result=mysql_query($query) or die('Error, insert query failed'); $array[] = array(); $numrows=mysql_num_rows($result); WHILE ($i < $numrows){ $allergies =mysql_result($result, $i, "allergies"); $vege = mysql_result($result,$i, "vege"); $age = mysql_result($result, $i,...

How do I count the total number of iterations within a loop?

ruby-on-rails,ruby,loops
I'm running a basic user photos system on a Ruby on Rails app. I want to count the total number of photos a user has. Can I do that with a Ruby method for counting the total number of iterations through a loop?? @photos.each do |photo| photo.total_number_of_iterations end ...

An error while looping a linear regression

r,loops,data.frame,regression
I would like to run a loop that will run per each category of one of the variables and produce a prediction per each regression so that the sum of the prediction variable will be deduced from the target variable .Here Is my toy data and code: df <- read.table(text...

Index out of Range exception in arrays

c#,loops
I am continuously getting out of range exception in my code. I went into the debug mode and found that it was giving an error for the zeroth index itself. Any help would be greatly appreciated. namespace StringTest7 { class Program { static void Main(string[] args) { Input(); StarGenerator(); RemovingWords();...

c++ mathematical calculations [closed]

c++,loops,math
I have to solve problem using c++, and can't really come up with solution. The condition is. In a skyscraper there are a lot of offices, on every office door there must be put plate with its number from 1 to the number of the last office. The plate can...

R - Check different matrices with a possible lag

r,loops,matrix,lag
This issue is quite tricky to explain but I am sure some of you already faced it. So I have two matrix. Matrix 1 (mat 1) and Matrix 2 (mat 2) What I want to do is to record in a third matrix (mat3) the value of mat2, after checking...

PHP foreach and continue [closed]

php,loops,foreach
I've come across a function in some code I'm trying to debug and I'm not sure why it is written like this foreach ($companies as $company) { if (!isset($company->account)) { continue; } some_function($company, $sectorsMap, $subSectorsMap); } Is this the same? foreach ($companies as $company) { if (!isset($company->account)) { some_function($company, $sectorsMap,...

Calling function and passing arguments multiple times

python,function,loops
I want to call the function multiple time and use it's returned argument everytime when it's called. For example: def myfunction(first, second, third): return (first+1,second+1,third+1) 1st call: myfunction(1,2,3) 2nd call is going to be pass returned variables: myfunction(2,3,4) and loop it until defined times. How can I do such loop?...

How to make function in loop run synchronously?

javascript,jquery,loops,google-chrome-extension,synchronization
Am working on a chrome plugin, and need to sendMessage from an 'app page' to a 'content script' and then get the return messages, from inside a loop. But since the loop doesn't wait for the sendMessage to return a value before starting on the next iteration, it is screwing...

Php counting with $i++

php,loops
I have this in a loop: <?php $i = 1; echo '<div id="'.$i.'">' . 'Anchor' . '</div>'; echo '<a href="#'.$i.'">' . 'Link-A ' . '</a>'; echo '<a href="#'.$i.'">' . 'Link-B ' . '</a>'; $i++; ?> This works fine if there is only one object. What do i have to do...

Array values are not being read correctly inside gameloop

javascript,arrays,loops
Im creating a program that displays random dots on a canvas, but I am running into problems when I give it rules specifying which dots are supposed to stay lit. I created a canvas with a matching array so for X number of pixels exist an object inside a 2D...

how to write a loop of the number of for loops in R?

r,loops
this is probably a simple one, but I somehow got stuck... I need to many loops to get the result of every sample in my support like the usual stacked loops: for (a in 1:N1){ for (b in 1:N2){ for (c in 1:N3){ ... } } } but the number...

call function after “loop” function for multiple elements is finished in jQuery

jquery,function,loops,animation
I've searched this site for a solution but couldn't find something to extract for my purpose. I have two functions. The first function fades in multiple elements in delay to each other until every element is faded in. Now I want to start the second function after the first is...

Run 3 variables at once in a python for loop.

python,loops,variables,csv,for-loop
For loop with multiple variables in python 2.7. Hello, I am not certain how to go about this, I have a function that goes to a site and downloads a .csv file. It saves the .csv file in a particular format: name_uniqueID_dataType.csv. here is the code import requests name =...

Excel 2013 vba refresh chart content after each iteration of For Loop

excel,vba,loops,iteration,refresh
Problem: Refresh graphical representaion of Series in ChartObject after each iteration of for loop Ex. y=m*Cos(x) y - Values m - parameter I have some data counted from formula with parameter. I want to visualise what influence has the change of parameter on XYgraph. I want to do it in...

R - loop and break after value found for each Rows

r,loops,matrix,break
I have a matrix of 0-1. What I would like to do is to loop into this matrix and search for the 1. Each time a 1 has been found, to simply jump or pass that row, in order to only record 1 value per row. What I am trying...

Jquery Loop appending image element just appends once

jquery,loops,dom
I'm trying to append an image element multiple times trough a loop, but it is only appearing once, any idea why? Here is my code $(document).ready(function() { var myImage = new Image(); myImage.src = 'image.jpg'; for(i=0; i < 12; i++) { $('#photos').append(myImage) } }); ...

Get next item in array using iterator using flags

javascript,jquery,loops,iterator,iteration
I am trying to obtain the next object in an object of objects (is you get my drift). I'm looking through the a list of songs, and trying to determine the next song to play. I use the flag playing to check if the song is being played, then i...

Callback in a double loop

loops,callback
I have seen examples of callbacks inside a loop where the loop needs to wait for the callback and I don't get how to apply those answers to my script. I actually have a double loop like that: var marker = [{43.000,-79.321},...]; var result = []; function test(){ for(var i=0;...

Matlab loop not working properly

matlab,loops,for-loop
largest = 0; num = 0; temp = 0; num_flip = 0; for x = 100 : 999 for y = x : 999 num = x*y; temp = num2str(num); num_flip = str2double(fliplr(temp)); if num/num_flip == 1 largest = num; one = x; two = y; end end end I'm...

Creating an auto incrementing loop within a function in python

python,loops,tkinter,increment
I'm trying to set up a loop that keeps track of a number of ordernums as well as assign a nw ordernum to each new order in increasing value. Here's the full code: *This is the fixed code using Klaus D. 's advice import tkinter from tkinter import * from...

Get return from javascript anonymous funcion in each loop(s)

javascript,jquery,loops,each
I've never worked with js before and now faced with a problem, how can I do next? function test() { $(xml).find("strengths").each(function() { $(this).each(function() { (if some condition) { //I want to break out from both each loops at the same time here. // And from main function too! } });...

javascript manipulating html elements in a php foreach

javascript,php,html,html5,loops
Consider the following: <? php foreach($queryResult as $res) : ?> // output all table columns <form onsubmit="return javascriptFunction(); " method="post"> <button id="b">edit</button> </form> <?php endforeach; ?> Obviously, when the javascript function is called, the id of the buttons are the same, so: document.getElementById(b).value; won't work as expected. Is it possible...

Grep for beginning of line while searching for a certain string

bash,loops
I have a file like such: 1 Role A 2 Role b What I'd like to do is search for the String "Role A" and return the value 1 in a variable. So something like the following: if grep "$i" role_info.txt then <assign a variable the number associated with the...

How to create bootstrap html structure in php loop?

php,html,loops,bootstrap
I'm using bootstrap and need to create structure like this <div class="row"> <div class="col-sm-3"> <!--content loop 1--> </div> <div class="col-sm-3"> <!--content loop 1--> </div> <div class="col-sm-3"> <!--content loop 2--> </div> <div class="col-sm-3"> <!--content loop 2--> </div> </div> <div class="row"> <div class="col-sm-3"> <!--content loop 3--> </div> <div class="col-sm-3"> <!--content loop 3-->...

for each loop: how to step out of conditions

loops,vbscript,condition
I am stuck at creating a loop for testing filenames with VBScript. To be precise, I am trying to perform something like a jump in a For Each loop. The loop should test all files in a folder and in some cases it should delete some files. But while running,...

How can I make my own timer without standard library?

c++,loops,timer
Is there some specific number of iterations, that I could make using a for loop, so that it exactly takes 1 second for the loop to be executed completely? For example the following code took 0.125s on my machine to execute: #include <iostream> #include <cmath> using namespace std; int main(){...

R - Remove columns with 0 values in df with 1 or more remaining columns

r,loops
I am writing a piece of R code which is looping through a dataframe and then running time series predictions from the subsetted dataframe. However, the manner in which I created the loop gives me a number of columns with 0 values. There could a single column with non zero...

Linq implementation of for and if loop

c#,linq,loops
This snippet below checks if eCode (an integer) is equal to any element in list1<int> and if yes, it does something. My question is the following.. what would be a linq implementation of this? I'm new to C# and Linq and not sure how to proceed. for (int i =...

Query With CONCAT and LOOP using SELECT

mysql,loops,concat
I got this kind of column: ------------------ |reference_number| ------------------ |1 | |12 | |123 | |1234 | |12345 | |123456 | |1234567 | |12345678 | |123456789 | |1234567890 | ------------------ I want to achieve this kind of output using mysql query: ------------------ |reference_number| ------------------ |0000000001 | |0000000012 | |0000000123 |...

Javascript how to start script on exact time

javascript,loops,time,setinterval
script will start on exact time (ex: 2015:06:15:00:00) If its on time, it will alert HELLO every 1 second. setInterval(function () {alert("Hello")}, 1000); could you please help me how to make this on up?...

How to create series of pandas dataframe by iteration

python,loops,pandas
I want to create df_2008 to df_2014 from an original df by iteration. df has columns names '2008' to '2014' and I want to seperate them into different dfs. I tried for i in range(2008, 2015): 'df_'+str(i)=df[str(i)] Which won't work. I would really appreciate it if anyone could help me....

Creating a number list with nested For loops in Python

python,loops,nested
I've been working on this now for well over four hours and i've tried to check several resources. I'm trying to get something like this: 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4...

JQuery loop on multiple items of the same CSS class

jquery,loops,each,keyup,word-count
I have multiple fields of the same class. The word count shows up correctly, but changes the value of every word count when one field has received input. Additionally, I'd expect the field to show a word count of 100 if no input exists, but it shows 0. Suggestions on...

How to match words in 2 list against another string of words without sub-string matching in Python?

python,regex,string,loops,twitter
I have 2 lists with keywords in them: slangNames = [Vikes, Demmies, D, MS Contin] riskNames = [enough, pop, final, stress, trade] i also have a dictionary called overallDict, that contains tweets. The key value pairs are {ID: Tweet text) For eg: {1:"Vikes is not enough for me", 2:"Demmies is...

How to retrieve filtered data from json with double for loop

javascript,json,loops,for-loop,filter
So i have build up this json file (http://www.smartbustracking.be/json/data.json) and now i am able to retrieve data. but what i would like to achieve is to filter data based on id with a for loop. i am able to show one item of a specific id but not all the...

echo both users

php,mysql,sql,database,loops
The code at the bottom of this post currently echoes: Name: Spongebob Squarepants Description: I live in a pineapple under the sea. Role: editor But there are two users in "wp_usermeta". It's only echoing one. The result needs to look like this: Name: wp_dev_05 Description: My name is Chris Topher!...

Escape out of 2 Javascript loops (or stop script)

javascript,loops
I have a quiz on my site that will submit if the time is up. After the form submits (via jquery), I would like the timer to stop working. I tried putting return: false after the test submits, but that didn't work. html: <span id="time">30:00</span> javascript: var thirtyMinutes = 60...

2 Foreach Loop Inside A Table

php,loops,laravel-4,foreach,blade
I had Users table and group table, when i load a group table, it loads the user which have same group_id as the group table id. it works, but my problem is the foreach was quite a mess. the output looks like this.. however, i want to make the output...

Lua in pairs with same order as it's written

loops,lua,order,lua-table
Is there any way to loop trough a table like the one below in the same order as it's written? local tbl = { ["hello"] = 1, [2] = 2, [50] = 3, ["bye"] = 4, [200] = 5 } What I mean is that when I use "in pairs"...

How to incrementally iterate through all possible values of a byte array of size n.

c#,loops,byte,bytearray
For my question n=16, but a generic answer would be appreciated too. So I have a byte array: byte[] key; My problem is that I want to iterate through all possible values of each element in this array, combined. I know this will take ages, and I'm not looking to...

printing an string in cross manner using c program

c,arrays,loops,for-loop,multidimensional-array
I'am trying to write a program for converting the given string in cross manner(i.e Diagonal from left-right and from right-left). If the string length is even it returns a message else arrange it in a cross form. The code is: #include<stdio.h> #include<string.h> int main() { char str[50]; char str2[50][50]; int...

Why is my C code printing out an extra line of rows?

c,loops,for-loop,macros,printf
#include <stdio.h> #define rows 500 //can define rows as any number int main() { int i,j; for(i=0;i<=rows;++i) { for(j=0;j<(2*i+1);++j) { printf("* "); } printf("\n"); } return 0; } So here is my code, what it does is it prints the number of rows set by #define and creates a right...

How do I format the logic for 3 conditions and use a previous condition as well?

java,loops,if-statement,while-loop,logic
NOT ASKING FOR ANYONE TO WRITE THE PROGRAM FOR ME I am having trouble understanding how to setup the logic for a program given these following conditions: For every day late up to and including 7 days, the late fee is $0.10/day After 7 days, for every day late up...

Can javascript for loop starts from negative number? [closed]

javascript,jquery,loops,for-loop
Here is a standard for loop: for (i=0; i<=5; i++) { el.append('<span>' + i + '</span>'); } This should append 11 spans with text from -5 up to 5, but this doesn't work at all... for (i=-5; i<=5; i++) { el.append('<span>' + i + '</span>'); } Is it possible to...

Loops to minimize function of arrays in python

python,arrays,loops,minimization
I have some large arrays each with i elements, call them X, Y, Z, for which I need to find some values a, b--where a and b are real numbers between 0 and 1--such that, for the following functions, r = X - a*Y - b*Z r_av = Sum(r)/i rms...

How to repeat this statement in R probably using apply()

r,loops
It might seem a silly question but how to repeat this line for 152 times and I would not like to use a for loop,since later it will not be efficient with larger data sets: reviews = as.vector(t(mydata)[,1]) mydata is a row in a data.frame and reviews is an array...

Using Yahoo! database without quantmod functions

r,loops,yahoo-finance
The problem I am trying to solve is looping a string through R with Yahoo! finance api. This would make a bunch of data frame files, but if I could convert it into xts, that would be awesome. However, the xts part is not as important. library(quantmod) DB <- quantmod:::DDB_Yahoo()...

How to build a 'for' loop with input$i in R Shiny

r,loops,for-loop,shiny
In my shiny app, I build a a number of checkboxes using a for loop, like this: landelist <- c("Danmark", "Tjekkiet", "Østrig", "Belgien", "Tyskland", "Sverige", "USA", "Norge", "Island") landecheckbox <- c() for (land in landelist){ landechek <- paste0("<label class=\"checkbox inline\"><input id=\"", land, "\" type=\"checkbox\" checked><span>", land, "</span></label>") landecheckbox <- c(landechek,...

Why this while loop cannot print 1,000 times per seconds?

java,loops,time,while-loop
The following Java method is meant to print the number i by nLoopsPerSecond times per second for seconds seconds: public void test(int nLoopsPerSecond, int seconds) { double secondsPerLoop = 1.0/(double)nLoopsPerSecond; long startTime = System.currentTimeMillis(); long currentTime; int i = 0; while ((currentTime = System.currentTimeMillis()) < startTime + seconds*1000) { System.out.println(i++);...

Matlab Calculating mean of distribution quantile in a for-loop

matlab,loops,for-loop,distribution,quantile
I am trying to calculate portfolio cVaR (conditional value at risk) levels from my simulated data for various portfolios. I am able to do that for one single portfolio using the following code: % Without a for-loop for series 1 test2 = test(:,1) VaR_Calib_EVT = 100 * quantile(test2, VarLevel_Calib); help1...

How to make sure to draw two different random cards [closed]

python,loops,random,while-loop
I have written code that should draw two different cards. However, I am not sure how I should end the while statement. Should I use break or continue? The while statement is there to make sure you don't draw two of the same cards. import random card_values = ["the Ace",...