Using SetInterval In Loops

Dec 15, 2007

i'm scratching my head over achieving similar results with setInterval() function, and how I can keep it from looping infinitely.

I want to do something like this:
var i = 0;
var endTime = now + ((1000*60)*2); // 2 minutes after now
while (now <=endTime) {
i = i + 1;
now = new Date().getTime();
document.write("total iterations: " + i);

however you can't do this because of lag issues, so i'll settle for using setinterval on its smallest interval of a millisecond, here is my attempt to translate the above to a setinterval solution:
var endTime = now + ((1000*60)*2); // 2 minutes after now
var intervalID = setInterval(loopFunc(endTime),1);
function loopFunc(endTime,intervalID) {
if (new Date().getTime() <= endTime) {
i = i + 1;
} else {

as you can see I have prolbems figuring out how to stop the interval from continuing to iterate, and passing the interval id, I'm clueless Also I'm clueless on echoing the total iterations via this method.

View 4 Replies


Get The SetInterval To Loop But When The SetInterval Is Called

Jan 5, 2010

I cant seem to get this to work.

I have this OO code and i want to get the setInterval to loop but when the setInterval is called, i get error saying that loop() is not define..

function setFunc(){
this.init = init;
function init(){


View 1 Replies View Related

While Loops

Nov 4, 2007

i am trying to do but I have no clue how to write it. Im trying to write a while loop that prints out all of the multiples of 5 between 10 and 95. I just need to know how to write the while loop i got everything else.

View 1 Replies View Related

Multiple Loops

Feb 6, 2006

I'm my script I've three loops processing a very huge data file. IE & Firefox show a message box after some time saying my script could be infinite looping and give me a chance to stop it.

Is there a way to prevent this dialog box to show up? I'm writing a script used only on a intranet and the final customer should not see the message box.

View 6 Replies View Related

Question About Loops

Jan 12, 2007

Hi, I want to have something like this:

function callme1() {

function callme2() {

function callme3() {

function callme4() {


except, it's going to be created in a loop, like

var x=0;
while (x<10) {

function callme[x]() {


So, out of that I would like to get 10 callme(1-10 or A-J) functions...
I guess I am lost which way to build this with the placement & parsing
of the variables.

View 3 Replies View Related

How To Break Out Of All Loops

Jun 6, 2009

Is it possible, when you have a loop in a loop, that when the inner loop reaches a certain point, it breaks out of both loops? For example:


The code above will break out of the (b=0;b<=10;b++) loop when b==5, but it will continue to do the a loop. not putting the first loop at all or making the first loop stop at 1): Is there a way to break out of both loops when the if condition is met? (I only ask that you not give a work-around because what I have in mind is much more complicated than this)

View 3 Replies View Related

Getting Averages From Loops?

Nov 8, 2009

I want to get averages from a for loop. Let's say I had a # of exams and in that loop I wanted to add the exams up and calculate the average. How would I go about doing this? Is this even possible in a for loop?

View 1 Replies View Related

Using While Loops Incrementer?

Jul 26, 2009

If I were to have a script:

Code JavaScript:
var numbers = [1, 2, 3, 4, 5];
var incrementer = 0;
while (incrementer < numbers.length)


View 1 Replies View Related

Cliping A String Without Loops

Jul 20, 2005

I have got a span inside a td of a table. i am trying to clip the
string that exceeds the length of the td and then put three dots
("...") after it so it will show that the text was clipped and when
the mouse hovers above it, it will show the title. now i have managed
to do all the above by puting a span inside the td with the style
overflow:hidden and it all works fine. to add the three dots i have to
clip the string to ten pixels below the length of the td and then add
the dots. i can do it by slicing the string in "string.length-1" each
time and then get the new length of the string with offsetWidth, and
when getting to the right length - add the dots. the problem is that
the slicing is done in a "while" loop, and when having a very long
table it takes too much time. the question is if there is any methods
of clipping the string by pixels or any other method that will shorten
the run time of the script.

i tried also having another span with the three dots that is
display:none and when the length exceeds the span length (the length
of the span is set to the td-10px) i change the display to block, but
the second span keeps on droping a line which is not good for me.

View 3 Replies View Related

IE With Nested Loops Isn't Working

Nov 21, 2009

I really can't figure out why it's not working in IE. The only problem I can think of would be using nested loops. Here's the part of the code that isn't working. It's not generating an error, it's just not returning anything. I know you guys hate when I post entire code, so I trimmed it down as much as I can. It's referring to an already stated xml document with xmlDoc. And it's goal is to return a table of rows that meet certain criteria. If you can see any syntax errors that explorer would not like, that's really what I'm asking for.


View 6 Replies View Related

Gets Xml But When It Loops It Empty The Page

Nov 30, 2011

I'm making a page which gets the contents of an xml file and creates a table and populates it. The problem is when it loops around it seems to strip everything from the page HTML, HEAD, BODY tags and everything inside of those and just puts the value of the elements from the xml file onto the page. My question is, am I able to perform this loop and keep the rest of the contents of the page intact? I've been trying for most of the day and I can't get this working.


View 1 Replies View Related

Loops And Execution Time

Nov 29, 2005

I would like to have two buttons on the page. When visitor clicks on first, I would like to start looping through numbers for example from 1 to 100. When loop gets to the end, I would like to start it over and stop it when user click on the next button.

My concern is if this is safe. What if user waits for 1 minute or more to click the second button which should stop the loop and pick up the number where it currenly is? Will it cause browser to warn user that the script is slowing down the browser? How can I avoid this?

View 11 Replies View Related

Multidimensional Arrays In Loops ?

Jul 11, 2010

While arr[i] works fine in a loop, the addition of another dimension...arr[0][i]...means that it will not accept an assigned value.

View 12 Replies View Related

Building A Table With For Loops?

Aug 16, 2010

point out where my logic is flawed in this? Or where my scripting is wrong?I'm trying to build a standard HTML table with 5 columns across and as many rows down as necessary, to fit all of the images in an array (brought into the DOM via PHP).My goal is to have rows of 5 columns that add on to accomodate up to 50 total images (10 rows).Here's my logic (flawed or not):*Look at the number of tems in the array*If the number is greater than 5, build one full row (of 5 <td>s)*Check again - is the number of items in the array greater than 10?*Build another row*If not, build a partial row, and fill in the rest of the <td>s (less than a full row) with blank spaces.The question is whether or not my logic is being represented in the javascript?unctions in <head>calls to function on lines 149-159Don't mind the formatting, I've blown it up so I can see what's going on.

View 4 Replies View Related

Set Variables Up And Call Them In 2 While Loops?

Dec 6, 2011

I want to start of by saying, i dont know much when it comes to javascript. I am trying to set variables up and call them in 2 while loops (one to set the variable, one later to try to call for it since I am putting it in an array) as I dont know how many I will be using when this code runs. To help understand what needs to be accomplihsed, I have commented out code on what I need to do, and left code beside it on what the sample is that actually works. I hope this is clear on what needs done.

HTML Code:
<script type="text/javascript">
var long_array=new Array();


View 5 Replies View Related

Linking With Arrays, For And If Loops?

Jun 25, 2010

I am having trouble with a project i am supposed to be doing which is to turn structured English into coding joined with the code i am about to post !This is the code i have written so far that works:

var contestantNamesArray = ['Tom and Nazia', 'Pat and Dan', 'Sandra and Kofi', 'Ian and Adele', 'Paul and Costas'];
var judgesPointsArray = [2,1,5,4,3];[code].....

I have tried myself but i am stuck at how to link the contestantNamesArray with the rest of the code in order to be able to display the couples who scored the maximum points and store it in a new variable and then write out the names.

View 10 Replies View Related

Function Won't Work With Loops?

Nov 28, 2010

We have created this function with loops and arrays Problem is the loops work only when I take out the function when the function is in place, nothing works, it is part of exercise

here is my code
title>Congressional Races</title>
<link href="results.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="votes.js"></script>
<script type="text/javascript">


View 5 Replies View Related

Average From Loops Without Arrays Nor Functions?

Oct 26, 2011

I've now got to form an average of snowfall inputs, taken from looped prompts, however I'm not allowed to use arrays or functions...Almost every example I see uses arrays, such as this one here: it possible to not use arrays to form the average? Please describe how to do this in general terms, as was highlighted in that link ^^^ I want to learn, not copy, although one can be derived from the other...What I haveso far, assume all vars have been announced.

for (var d=1; d<=numofinputs; d=d+1)
input = prompt("Enter a data input" + d)

View 4 Replies View Related

Make A Hollow Square For Loops?

Oct 26, 2009

I am trying to make a hollow square for loops this is what i got but i dont want my loop to go infinite i just want my loop to stop after first time.

<script type="text/javascript">
var squareSize;


View 8 Replies View Related

Create A Pyramid With Nested For Loops

Feb 27, 2010

I have to create a pyramid with nested for loops in javascript. This wasn't a problem until my professor asked us to mirror the pyramid. this is the code i have so far:


This part of the program works. What I'm having trouble with, is placing spaces and x's on the left side so that the triangle appears like:

I saw a few thread that had the right half of this triangle upside down, but I couldn't figure out how to flip it and fill in the other side. I'll attach the .html file so people can run what I have so far.

View 1 Replies View Related

Guessing Game Using Loops And If Statements

Dec 5, 2010

We have to create a number guessing game with a random number between 1 and 50. With a loop that runs exactly 10 times or until you get the number and gives hints that say guess higher or lower. I don't know what I am doing wrong this wont work at all. I am generally lost?
lab14a_KENTDL.html (3.48K)
Number of downloads: 52

View 1 Replies View Related

Trouble With Loops And Arrays In Java

Nov 14, 2000

I've been working on trying to compile this bit of Java code. It's taken from an existing code (with permission) that I know works. The problems started when I added an array. Code:

View 6 Replies View Related

Creating A M*n Table Using Functions And For Loops?

Oct 16, 2011

Write a script to generate two random numbers for variable m and n, the values generated for the variables should range from 1 to 10. We want to make an m * n table (m rows and n columns) with the word Hello in each of its cells. Now define a function f with one parameter n that displays n columns of one row of the table (You need a for-loop). Call this function m times to display m rows of the table. For example if m = 6 and n = 4 we should get the following:



(The above is supposed to be a table but did not copy fully)This was my attempt, although i really did not know how to attack this.

<script type="text/javascript">
function f(n)


View 4 Replies View Related

Making One Loop From Many Small Loops?

Nov 27, 2010

How would I make this into one Loop using all same variables? Right now I can only get his program to work with separate loops

Here is the Coding
script type="text/javascript">
for (var i=0; i<date.length; i++){


View 5 Replies View Related

Nested Loops To Work Through The Images

Nov 15, 2010

I'm having trouble getting this nested loop to work. It only outputs the last image and I want it to loop through the images.


View 2 Replies View Related

Does Firefox Have Alimit On The Number Of Loops Dne With Settimeout?

Aug 22, 2006

I have created a script that needs to constanstly poll a webpage, I do
this with a controling function that fires off different functions to
do the work, then restarts by calling itself after a second using

on IE it runs forever, on firefox it stops after a while,

what am I doing wrong?

is there a limit on the number of times you can go around this type
loop you can go around in firefox?

if there is a limit, how do I get around it?

Would it be freak out if the function is already running when it is
fired again?

View 2 Replies View Related

Copyrights 2005-15, All rights reserved