loops

How to loop a try catch statement?

流过昼夜 提交于 2020-01-23 09:00:16
问题 How do you loop a try/catch statement? I'm making a program that is reading in a file using a Scanner and it's reading it from the keyboard. So what I want is if the file does not exist, the program will say "This file does not exist please try again." then have the user type in a different file name. I have tried a couple different ways to try an do this but, all of my attempts end up with the program crashing. Here is what I have try { System.out.println("Please enter the name of the file:

how to exit from two nested for loop in matlab

大兔子大兔子 提交于 2020-01-23 06:45:30
问题 I have a while loop in which I have two for loops. I have a condition in the innermost for loop. Whenever that condition is satisfied I want to exit from both the two for loops and continue within the while loop: while (1) for x=1:20 for y=1:30 if(condition) end end end end Does Matlab have something like a labeled statement in Java, or is there another way to do this? 回答1: Here is a very simple answer leveraging the fact that testing numerous simple conditions is nearly free: while (1) go =

PHP get CSV from URL, load into array, format

老子叫甜甜 提交于 2020-01-23 06:30:29
问题 I am trying to write a script to download historic data from yahoo finance as a csv. My script successfully loads the data into an array but I've run into two problems. First is that despite creating a date range for it to pull from yahoo, I keep getting the entire historical data for that stock and I'm not sure why.I only want the last 6months calculated back from current day. Second, I was able to use str_getcsv to load the data into an array, however I have been unable to create a loop

PHP get CSV from URL, load into array, format

久未见 提交于 2020-01-23 06:30:24
问题 I am trying to write a script to download historic data from yahoo finance as a csv. My script successfully loads the data into an array but I've run into two problems. First is that despite creating a date range for it to pull from yahoo, I keep getting the entire historical data for that stock and I'm not sure why.I only want the last 6months calculated back from current day. Second, I was able to use str_getcsv to load the data into an array, however I have been unable to create a loop

Iterate through methods and properties of an ES6 class

久未见 提交于 2020-01-23 06:28:53
问题 So with the growth of new frameworks with JavaScript many have adopted ECMAScript 6 shim's or TypeScript, with many new features. My question is this: How does one iterate over the methods/properties of an ES6 class? e.g. (with objects) var obj = { prop: 'this is a property', something: 256, method: function() { console.log('you have invoked a method'); } } for (var key in obj) { console.log(key); } // => 'prop' // => 'something' // => 'method' (with classes) class MyClass { constructor() {

Modifier inside update function HTML5 Canvas Game?

梦想与她 提交于 2020-01-23 03:30:08
问题 I've seen this kinda structure inside the update function in HTML5, Canvas games, with a "modifier" variable: function update(modifier) { obj.x += obj.speed * modifier obj.y += obj.speed * modifier } function main() { var thisLoop = new Date var delta = thisLoop - lastLoop update(delta / 1000) render() var lastLoop = new Date } var lastLoop = new Date setInterval(main, 1) Now I use myself this structure: function update() { obj.x += obj.speed obj.y += obj.speed render() window

jquery loop animation

岁酱吖の 提交于 2020-01-23 03:13:22
问题 i have these scrip that i need to loop: $(document).ready(function() { runIt(); }) function resets() { $('.grower').removeAttr("style"); } function runIt() { $('.grower').animate({width: "30px",height: '30px', left: "-6", top: "-6", opacity:"0"}, 800, resets); } but when i add the runIt(); inside it self so it can loop, it loops but my browser goes blank and i will not respond. how can i do it so it will loop that animation. thanks in advance 回答1: No need to query the DOM constantly. Store

How to produce combinations iteratively in R? [duplicate]

浪尽此生 提交于 2020-01-23 02:12:27
问题 This question already has an answer here : How do I find all possible subsets of a set iteratively in R? (1 answer) Closed 6 years ago . So I am currently using the following code to generate my combinations: combn(x,y) But the thing is that function stores all of the possible combinations. I dont want to store them, I just want to produce them through like a loop or something. It would be way more efficient for my program. Is there a way to generate combinations through a for loop rather

How to produce combinations iteratively in R? [duplicate]

蓝咒 提交于 2020-01-23 02:12:06
问题 This question already has an answer here : How do I find all possible subsets of a set iteratively in R? (1 answer) Closed 6 years ago . So I am currently using the following code to generate my combinations: combn(x,y) But the thing is that function stores all of the possible combinations. I dont want to store them, I just want to produce them through like a loop or something. It would be way more efficient for my program. Is there a way to generate combinations through a for loop rather

What's the higher-performance alternative to for-loops for subsetting data by group-id?

╄→尐↘猪︶ㄣ 提交于 2020-01-22 14:38:12
问题 A recurring analysis paradigm I encounter in my research is the need to subset based on all different group id values, performing statistical analysis on each group in turn, and putting the results in an output matrix for further processing/summarizing. How I typically do this in R is something like the following: data.mat <- read.csv("...") groupids <- unique(data.mat$ID) #Assume there are then 100 unique groups results <- matrix(rep("NA",300),ncol=3,nrow=100) for(i in 1:100) { tempmat <-