What is Loop: Definition and 1000 Discussions

In computer science, a for-loop (or simply for loop) is a control flow statement for specifying iteration, which allows code to be executed repeatedly. Various keywords are used to specify this statement: descendants of ALGOL use "for", while descendants of Fortran use "do". There are other possibilities, for example COBOL which uses "PERFORM VARYING".
A for-loop has two parts: a header specifying the iteration, and a body which is executed once per iteration. The header often declares an explicit loop counter or loop variable, which allows the body to know which iteration is being executed. For-loops are typically used when the number of iterations is known before entering the loop. For-loops can be thought of as shorthands for while-loops which increment and test a loop variable.
The name for-loop comes from the word for, which is used as the keyword in many programming languages to introduce a for-loop. The term in English dates to ALGOL 58 and was popularized in the influential later ALGOL 60; it is the direct translation of the earlier German für, used in Superplan (1949–1951) by Heinz Rutishauser, who also was involved in defining ALGOL 58 and ALGOL 60. The loop body is executed "for" the given values of the loop variable, though this is more explicit in the ALGOL version of the statement, in which a list of possible values and/or increments can be specified.
In FORTRAN and PL/I, the keyword DO is used for the same thing and it is called a do-loop; this is different from a do-while loop.

View More On Wikipedia.org
  1. G

    Marble loop roller coaster launcher

    Help me here. I need to figure out how to launch a marble so it navigates a vertical loop, then follows projectile motion at the end of the loop The design must use elastic potential energy to do this and must consistantly launch it consistantly to a specifyied location. I can't figure...
  2. P

    C/C++ Can someone explain why this isn't an infinite loop? (C++)

    This was a question from my C++ midterm. I see an infinite loop, but the correct answer is 12. Can anyone explain this? Question: What is the value of i after the loop exits? int i; for(i=0; i < 10; i++) i+=3; i=1;
  3. jegues

    Induced EMF Moving Current Loop

    Homework Statement See figure attached. Homework Equations The Attempt at a Solution I'm having some confusion about the negative sign within this problem. If you compute the curl of the expression shown in the figure you'll find that it's equal to, -10v_{0} \hat{k} But...
  4. R

    Constructing a Feynman loop integral

    Homework Statement I need to construct the Feynman loop integral for the following diagram: (*) where \nuL is the left-handed neutrino, \phi is a scalar particle and N is a heavy neutrino with a Majorana mass. Homework Equations N/A The Attempt at a Solution I'm trying to determine it...
  5. L

    Need to interrupt a low voltage lighting loop circuit

    Need to interrupt a low voltage lighting "loop" circuit I configure a lot of low voltage lighting for a living. Although it's not a deal-breaker for the project I'm working on, I'm having a disagreement with a colleague as to whether the following configuration should work: Shapeable...
  6. I

    Magnetic H field for a rectangular loop antenna

    Hi, Homework Statement How can I calculate the magnetic H field for a rectangular loop antenna (L x W) at a distance of x, which is made from copper tape with 30 um thickness and width of the tape from 1 to 5 cm. For the same antenna made ​​of wire I applied next formula...
  7. smokingwheels

    Frequency to period adjustment in program loop calculation

    Homework Statement Adjust a program loop so frequency will change linearly with a keyboard increment or decrement. The current calculation adjusts about 40 counts in the delay loop but when the frequency gets high the step is frequency is very large with each decrement in the loop. A...
  8. N

    A boy, a cart, a loop , an icecream-cone

    Was sitting in class thinking about this problem, did some rough sketches of a solution but never really managed to solve it. ![Ice cream cone and a loop-de-loop][1] The problem boiled down to finding out how much time the boy uses getting from the top of the loop to the bottom. Any...
  9. T

    Can PLL Achieve Phase Lock & Frequency Lock?

    can the PLL achieve phase lock and not frequency lock? and can the PLL achieve frequency lock and not phase lock? Please advise. Thank You
  10. L

    How to Exit a For Loop in C Programming

    Hello everyone! I just start using C programming as i execute a numerical method in MATlab for a heat diffusion problem. I have solve my problem but my code can be a little better. HERE is part of my code and i use comments to ask for help! for i=2:10 E(i,1)=20; T(i,1)=1...
  11. C

    Stumped by Basic Kirchhoff's Loop Rule Question

    Kirchhoff's Loop Rule: The directed sum of the electrical potential differences (voltage) around any closed circuit is zero. I'm an electron. I'm in a single loop series circuit with just a 5 volt battery and a resistor. The battery gives me a voltage boost of 5 volts and sends me on my way...
  12. K

    Wire loop parallel to and above an infinite plane of iron

    Homework Statement A wire Loop R with a current I=10A running through it, is distance d above an infinite plane of iron with mu=5mu_0 R=2d. Find the force on the loop Homework Equations I would assume you could use image currents in the plane of iron to solve this The Attempt at a...
  13. K

    Solving Faraday's Law for Rotating Loop Motion

    Homework Statement A square loop with sides l is centered on the origin and fixed in the center so it is free to rotate around the x-axis. A magnetic field is changing with time B=B_0(1-exp(-a*t)). I need to find a differential equation to describe the motion of the rotating loop...
  14. K

    IF loop within a FOR loop problem

    I am editing code which was developed to model a mass spring damper system in the time domain using the equations of motion of the system. One damping ratio in particular,cpto, was constant originally but I am trying to vary it according to the if statement below. if k3*(x2(i)-x1(i))>=0 &&...
  15. S

    Exploring Time Loops: Quantum Entanglement and Superluminal Exchange Experiments

    They say that if quantum entanglement were meditated by actually superluminal exchange, causality is not violated because you can't use it to send information. This is because quantum randomness can't be control. But note there is still actual exchange of randomness information between past and...
  16. M

    Matlab, for loop, sawtooth function

    [b]1.Hi! i am having problems plotting a sawtooth waveform without the use of the sawtooth function in matlab. I am required to produce a sawtooth waveform with a duty cycle of 30% using nested loops (for loop within a for loop) i have managed to get the ramp function from one, for...
  17. M

    Rollercoaster velocity question, only given: radius of loop.

    Homework Statement The rollercoaster moves freely without negligible friction. The radius of the loop is 20m and the car barely makes it through the loop. Find the speed at position 3. Find the speed at position 1 and 2. Find the difference in height between position 1 and 4 if the speed...
  18. C

    Finding Torque on current loop.

    Homework Statement The current loop is in the y-z plane. The direction of the magnetic field is in the z-direction. A) Which way is the torque on the current loop? B) If the current is 4 amps and the magnetic field strength is 2.5 Tesla, what is the magnitude of the torque? here is the...
  19. C

    Find the power required to pull loop through constant magnetic field

    Homework Statement The wire shown is being pulled through a constant magnetic field of 0.25 Tesla at 3 m/s. A) Find the power required to pull the loop at this speed. B) If the wire has a resistance of 100 ohms, what is the current in the wire? Homework Equations The Attempt at...
  20. D

    Minumum velocity when entering a loop?

    A small object goes down a ramp and through a loop with a 2 metre diameter. In order to complete the loop, what is the minimum speed the object must have when reaching the bottom of the ramp? (consider there is no friction) a) 5 m/s b) 0 m/s c) 3 m/s d) 7 m/s I'm a bit clueless on...
  21. K

    What is the recent development of Loop Quantum Gravity

    Recently, I am very interested in Loop Quantum Gravity. But I hope I can know more about the recent development of Loop Quantum Gravity. I mean the development from 2000 to 2011. Any conceptual or practical or technical development in this realm? Further more, I do not know the relationship...
  22. A

    Roller coaster cart gaining weight into a loop

    Homework Statement A roller-coaster car starts from rest at a high point 2 times as high as the top of the loop-the-loop. When it is just about to enter the loop from the bottom, a 100 lb bag of bricks fall on the car, causing it to lose 25% of its speed. Neglecting friction, do you think the...
  23. I

    Induced current in a loop circuit magnetic field

    Homework Statement Homework Equations I know this is supposed to use Lenz's law, but I don't really understand it V=IR The Attempt at a Solution I calculated the resistance of the circuit to be 6.4e-6 / .0015 = 0.00426666667, but that's as far as i know what to do
  24. stripes

    Comp Sci Declaring an array in a for loop (Java) or similar

    Homework Statement I need to create a loop that asks the user to input double numbers into an array. The number of elements in the array is not predefined; the user will continue to enter numbers as long as they wish until a NEGATIVE number is entered, at which point the control will exit...
  25. P

    Rotational Motion Speed at the top of the loop

    Homework Statement 12. A motorcycle travels around a vertical 12 m radius loop. What is its speed at the top of the loop if the normal force exerted by the seat on the driver is equal to ¼ of his weight? a. 7 m/s b. 8.1 m/s *c. 9.4 m/s d. 15 m/s e. 88 m/s Homework Equations...
  26. A

    Java I with this java program that has to use do while loop?

    here is import java.util.*; public class oddNumbers { public static void main(String[] args){ System.out.println("enter two number"); Scanner kb=new Scanner(System .in); int number=kb.nextInt(); int number2=kb.nextInt(); int s=number2/2; String decision...
  27. tom.stoer

    Prospects of spin foam formalism in loop quantum gravity [Alexandrov, Roche]

    I would like to continue discussing SF (i.e. PI) models of LQG based on chapter 3 from http://arxiv.org/abs/1009.4475 Critical Overview of Loops and Foams Authors: Sergei Alexandrov, Philippe Roche (Submitted on 22 Sep 2010) Abstract: This is a review of the present status of loop and...
  28. S

    Pressure Calculation in Closed Loop PV Thermal

    Hi I am trying to design a closed loop testing system for a solar thermal system using water as the heat transfer medium. There a number of fittings and and pipework involved, the water might reach temperatures up to 80/90 deg C. I am trying to calculate what the max pressure in the...
  29. tom.stoer

    Prospects of the canonical formalism in loop quantum gravity [Alexandrov, Roche]

    I would like to continue discussing canonical LQG based on chapter 2 from http://arxiv.org/abs/1009.4475 Critical Overview of Loops and Foams Authors: Sergei Alexandrov, Philippe Roche (Submitted on 22 Sep 2010) Abstract: This is a review of the present status of loop and spin foam...
  30. genxium

    A question about the loop gain and source contained port impedance

    Homework Statement I recently got a problem that confuses for days, the picture for this problem is in the attachment field, is there someone can tell me that, if an oscillator is topology is described using the negative impedance model in the picture, should I have R>r to ensure that the...
  31. marcus

    What's happening with Loop? (new potential challenges)

    Some new research has emerged as a potential challenge to the main Loop version of quantum geometry/gravity. We may disagree as to which new work presents the most interesting challenge, I want to know what you think. I personally think that the Freidel Geiller Ziprick (FGZ) paper that just...
  32. H

    Comp Sci Java infinite loop (problem statement)

    Homework Statement http://pastebin.com/7ehbwkvE expires in 1 month... the problem statement is very vague... we are given this code of an infinite loop, and need to fix the problem that it poses by either using a correct while loop or a for loop. Homework Equations The Attempt at a...
  33. S

    Work done by rectangular wire loop with current in magnetic field

    Homework Statement A rectangular wire loop of height h and width w, centered on the origin, carries current I in the direction shown in the figure. The angle between the positive x-axis and the plane of the loop is θ, defined as shown in the figure below. (When θ = 0 the loop lies in the x-z...
  34. V

    Solving a Complex Circuit: Loop Analysis & Node Analysis

    Homework Statement [PLAIN]http://img856.imageshack.us/img856/8508/circuit.png Homework Equations Loop Analysis and Node Analysis The Attempt at a Solution The Question states I have to find the equivalent resistance within the circuit. But, since there is a dependent source...
  35. S

    Circular loop magnetic field

    Homework Statement As shown in the figure below, a circular loop of radius a = 0.1 m lies in the horizontal x-y plane with its center located at the origin, with steady current I = 2.0 A circulating in a counter-clockwise direction in the loop. The magnetic field strength B(0,0,z) at the...
  36. S

    What Determines the Direction of Rotation in a Current Loop?

    Homework Statement Consider a long wire running in the vertical direction with a rectangular loop of wire beside it as shown. Now suppose that a constant current, I, flows upward along the long wire, and the same magnitude current, I, flows clockwise in the loop. As viewed from the top...
  37. A

    Mathematica Defining one matrix in terms of another in Mathematica with FOR loop

    THIS ISN'T WORKING AT ALL! I'm trying to define a matrix M in terms of a predefined matrix N by using the following for loop: For[a=1,a<=12,a++,M[[a,a]]=N[[1,a]]] So I just want the diagonal of M to be the first row of N. But this is not working at ALL. Does anyone see what I'm doing wrong?
  38. K

    Knot Tie-ing: Adjustable loop and knot that gets more secure as its pulled

    I do some rock climbing, and the most common knot you see is the double-figure 8: That's because you can tie it at any point in the rope to create a loop for other climbers to latch into. It also gets tighter as you pull from any direction: the loop or either of the two single ropes coming...
  39. R

    Is it safe to loop the inverter's output neutral to loop with the mains neutal?

    Is it safe to loop the inverter's output neutral to loop with the mains neutal?? Guys, I need a help on this. I thought that it is rather safe to loop one of the output terminal of the inverter to loop with the mains supply inverter, so that there doesn't arise the need of extra neutral wiring...
  40. C

    Loop-the-loop find height object falls out of the loop

    Homework Statement m= 0.2Kg r=0.6m k= 500N/m x=0.08m the spring is pressed together 0.08m before it's released. Friction = 0. the objekt goes through a loop. find the height when the object loses contact with the loop. Homework Equations The Attempt at a Solution 1/2kx2=...
  41. P

    Comp Sci Stop Input with Control Z: Java Loop

    I am having the user enter a bunch of strings and when the user wants to stop entering them I want him to use control z to stop the input. The only problem is I can't seem to figure how to make that happen, does anyone have any suggestions?
  42. marcus

    Loop bounce and geometric entropy (re: Bill A's question)

    Bill Alsept started a thread raising the general question---do cosmic models with regularly repeating big bangs conflict with thermodynamics' 2nd Law? (The law to the effect that, where it can be defined, entropy does not decrease, or does so only by rare accident, at irregular intervals if at...
  43. H

    Comp Sci Looping Through ASCII Art in Java: Solving a Homework Predicament

    ..so, we have been assigned a homework to print a certain ASCII art using only loops and methods. We can also use the built-in math methods such as the exponential one and whatnot. Basically, we have been asked to print an increasing loop that goes as follows: * ***...
  44. P

    For Loop Conditions in C: How Do You Combine Multiple Conditions?

    i know that it is possible to have multiple conditions in a for loop. but is it separated by a comma or would it be separated by && like in an if statement? Thanks
  45. N

    What Are Common Problems with Inductive Loop Relays?

    Hi all Well I tried googling this but could not find a satisfactory answer , so here I am seeking help from all you experts :biggrin: So my question is regarding inductive loop sensors used on the road to give presence, vehicle classification etc information. These inductive loops are...
  46. I

    Conservation of energy on loop. Nearly done

    Homework Statement A 1500-kg roller coaster car starts from rest at a height H=23.0m above the bottom of a 15.0-m-diameter loop. If friction is negligible, determine the downward force of the rails on the car when the upside-down car is at the top of the loop.Homework Equations Conservation of...
  47. S

    Solving for Speed: Roller Coaster at the Top of a Loop

    Homework Statement The normal force equals the magnitude of the gravitational force as a roller coaster car crosses the top of a 46m--diameter loop-the-loop. Homework Equations What is the car's speed at the top? The Attempt at a Solution the answer is in m/s I have several...
  48. G

    Loop analysis with complex components

    I'm supposed to find the currents flowing through the circuit. While loop analysis is pretty easy, converting a bunch of complex numbers back and forth can get complicated fast. I'm not asking for the exact answer, but please look through the solution to verify if my working is correct. Many thanks.
  49. tom.stoer

    Prospects of the canonical formalism in loop quantum gravity

    There are still unsettled questions in loop quantum gravity, especially regarding uniqueness of the Hamiltonian constraint, constraint algebra, on-shell vs. off-shell closure, operator norm and convergence, ultra-locality, possibly quantization anomalies. These questions have been asked in...
  50. E

    What Is the Correct Approach to Solve This Loop Analysis Problem?

    Homework Statement http://i.imgur.com/pVIMw.png" Homework Equations The Attempt at a Solution I called the top left loop i1, the top right loop i2, the bottom right loop i3, and the bottom left loop i4. I have all of these currents going clockwise in my work. An attempt to do loop analysis...
Back
Top