Loop Definition and 1000 Threads

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. Z

    Loop Running Time: O(n) Not O(n2)

    Can someone explain why the running time of following piece of pseudo code is O(n) and not O(n2)? for i := 0 to n - 1 while A[A[i]] != A[i] swap(A[i], A[A[i]]) end while end for The for loop executes at most n times and the inner while loop executes at most n-1 times...
  2. K

    Could I treat this as a closed loop?

    Could I treat this picture as a closed loop? This is part of a much larger problem, so this is all I need to know. I think I can because the ends go off to infinity, but I'm not sure. http://i.imgur.com/RFCsrqH.jpg
  3. C

    Using Farady's law with a closed loop.

    Homework Statement The figure below shows two circular regions R1 and R2 with radii r1 = 20.0 cm and r2 = 32.9 cm. In R1 there is a uniform magnetic field of magnitude B1 = 52.4 mT directed into the page, and in R2 there is a uniform magnetic field of magnitude B2 = 75.6 mT directed out of...
  4. M

    Double integral for loop of rose r=cos2θ

    Homework Statement Homework Equations The Attempt at a Solution Solution is given. I don't understand how +-∏/4 is found as a range for θ Also why is 0 <= r <= cos2θ r is always r which is defined as cos2θ
  5. S

    Find the max induced EMF in the loop by the changing loop

    Homework Statement I have attached the two questions. the first has a diagram. 1. Find the MAX Induced EMF (in volts) in the loop by the changing current? 2. What is the magnitude of the EMF induced in the loop by the changing current at t=.8 (seconds) answer in Volts? Homework...
  6. A

    Kirchoff's Loop Rule-Direction of Current?

    Kirchoff's Loop Rule--Direction of Current? I came across this question, and it really confused me-- how does the current decide which direction it goes? The pictures are attatched below. The first picture is of the original questions. It gives two scenarios, and asks you what the value...
  7. A

    Induced Current for a Solenoid Pulled Away From Loop

    Homework Statement Sorry for the blurry picture. If the coil is being pulled away from the loop shown to the right, in what direction is the current induced in the loop? Homework Equations right-hand rulesThe Attempt at a Solution I assumed it to be clockwise just from looking at the...
  8. M

    How to find height of original hill (roller coaster loop problem)

    Homework Statement Radius of loop: 20 m Mass of cart: 225 kg Gravity: 10 m/s/s (once I figure out how to do this I'll use 9.8 in the final project) Found so far: B) Velocity (top of loop) = 14.14 m/s C) GPE at the top of the loop = 90000 N C) KE top of loop = 22500 N D) KE (bot) =...
  9. Safinaz

    How to Calculate the Loop Function for Higgs Decay to Photons or Gluons?

    Hi all, Has anyone know how to calculate the loop function of Higgs decay to photons/ gluons by t quark , or a useful reference. Cheers, Safinaz
  10. AJKing

    EMF in a loop; non-constant magnetic field

    Homework Statement Refer to Figure attached. The current in the long straight wire is i = (4.5A/s2)t2-(10A/s)t Find the EMF in the square loop at t=3.0s.Homework Equations \xi = -\frac{d \Phi}{dt} And Biot-Savart law for straight wires of infinite length: B = \frac{\mu_0 i}{2 \pi R}The...
  11. JJBladester

    Assembly Loop: How many times does NOP run?

    Homework Statement How many NOP instructions are run in the nested loop below? OUTER DW 4000 ;outer loop count INNER DW 62000 ;inner loop count MOV DX,OUTER WAIT1: MOV CX,INNER WAIT2: NOP NOP NOP NOP...
  12. stripes

    Show the loop integral of Poynting vector is zero for plane waves

    Homework Statement Show that for plane waves, the following result holds: \oint \textbf{S}\cdot d \ell = 0. Homework Equations -- The Attempt at a Solution \oint \textbf{S}\cdot d \ell = \frac{1}{\mu_{0}}\oint (\textbf{E} \times \textbf{B})\cdot d \ell Now do I just use...
  13. H

    Moving Square Loop through a Magnetic Field

    Homework Statement A square loop of side 1.5m and Resistance 2Ω is pulled with a constant velocity v=0.3m/s through a smaller region with a constant magnetic field B (out of the page) of 4T. The figure shows the position at t=0. Calculate the magnetic flux of the coil at t=4s.. Here is a...
  14. T

    Square Loop Moving Through Varying Magnetic Field

    Homework Statement A square loop of side length L is moving in the x direction with velocity v. v=vx. B points along the z axis and is defined by B=αxez where α is a constant. Find EMF along the loop Hint: Find forces on charges in rod by virtue of motion of the rod.Homework Equations...
  15. S

    Magnetic field at (z) axis of square loop

    Homework Statement We have a square loop with side length 2a, at xy plane. Now we know ( I have calculated ) that the magnetic field at the center of the square loop to be H = \frac{2I}{\sqrt{2} \pi a} Now we want to know what is the magnetic field at point P, which is on the axis which...
  16. W

    Moving a loop of wire away from a current carrying wire

    Homework Statement Hey all, I am studying for the GRE and I need help with this question: A rectangular loop of wire with dimensions shown above (see attachment) is coplanar with a long wire carrying current I. The distance between the wire and the left side of the loop is r. The loop is...
  17. S

    Fortran [fortran90] having problem to call back the value from previous loop

    hi all, I wrote programming code for fdtd 2d tfsf in fortran 90 as below: !simulation for tmz mode incident plane in 2d subroutine tfsf2d implicit none double precision :: f0,miu,eps,delta,S,c,lambda,E0,N0 double precision :: deltat integer...
  18. V

    How Do You Calculate K for a Closed Loop Damping Ratio in Higher Order Systems?

    From control systems: I am asked to find the value of K that gives the closed loop damping ratio of 1/sqrt2. The value for the complimentary sensitivity is T(S)=(2KS +4K)/(s^3 +162S^2 +(320+2K)S +4K) so how do I find the value for K? I tried putting it in the general equation, but it...
  19. M

    Position analysis of slider crank like mechanism using loop equations

    Hi Everyone, This is my first post so bare with me. Firstly, a bit of background about the problem. I am designing a near rear drive train for a formula student car which incorporates a chain tensioning device linking the differential to the rear of the chassis. Essentially I am wanting...
  20. J

    Wire loop placed in B field which is decreasing uniformly

    Homework Statement A wire loop of area 2·0×10−4 m2 contains 40 turns, and has a total resistance of 40Ω. The plane of the loop is perpendicular to a uniform magnetic field of magnitude B0. The magnetic field is now turned off such that the flux through the loop drops linearly to zero. A total...
  21. A

    Double Integral One Loop of the Rose

    Homework Statement Use a double integral to find the area of one loop of the rose r = cos 3\theta Homework Equations The Attempt at a Solution This is a past test question. The only thing I got wrong was the set up while I got the rest of the mechanical steps right. I set up as...
  22. F

    Solving Two Loop RC Circuit Homework

    Homework Statement A circuit is constructed with four resistors, one capacitor, one battery and a switch as shown. The values for the resistors are: R1 = R2 = 52 Ω, R3 = 41 Ω and R4 = 129 Ω. The capacitance is C = 62 μF and the battery voltage is V = 24 V. 1) The switch has been open for a...
  23. P

    Current Loop in a nonuniform magnetic field

    Homework Statement A nonuniform magnetic field exerts a net force on a current loop of radius R. The figure shows a magnetic field that is diverging from the end of a bar magnet. The magnetic field B at the position of the current loop makes an angle θ with respect to the vertical, as the...
  24. R

    Comp Sci Fortran DO Statements (how many loop times)

    Hello, Examining the following DO statements and determining how many times each loop will be executed. Assume that all loop index variables are integers. (a) DO irange = -32768, 32767 (b) DO j = 100, 1, -10 (c) DO count = 2, 3, 4 (d) DO index = -4, -7 (e) DO i = -10, 10, 10 The loop will...
  25. T

    Use results of a 'for' loop to formulate a vector

    I would think this should be an easy one... For i=0 to i=M, I want to run a a calculation and get M different results. I want to store those M results as a vector so I can plot them. Simplify version below: for i=0:10 T = i/2; T end This spits out a list of numbers: 0...
  26. A

    What Is the Probability of Winning in a Gambler's Ruin Scenario?

    Hi guys, I have been given a problem to complete, but at the moment my progress has been minimal. I have only had two classes on using Matlab since September, thus I am not very experienced. To complete this problem I know I need to use nested For loops but I just don't know where to...
  27. Q

    How to Use Trapezoid Method with 3 Loops in MATLAB for Numeric Integration

    dear users I want to do a triple integration over x ,y ,z in MATLAB but because my expression under the integral is so complicated I want to change integrals to sum by Trapezoid method using a loop in MATLAB but for doing that I have 3 integrals and so 3 for loops for summing over x , y , z...
  28. L

    Where to get started in Loop Quantum Gravity?

    Hi, I wasn't sure where to post this so I hope it's ok to post my questions here. I would like to learn the basic fundamentals of Loop Quantum Gravity as efficiently as possible. I'm currently 63 years old. I majored in Physics and Chemistry eons ago, and so I'm rusty on everything but...
  29. G

    How Is Charge Calculated in a Two Loop RC Circuit After the Switch Opens?

    Homework Statement A circuit is constructed with four resistors, one capacitor, one battery and a switch as shown. The values for the resistors are: R1 = R2 = 22 Ω, R3 = 91 Ω and R4 = 129 Ω. The capacitance is C = 40 μF and the battery voltage is V = 12 V. The positive terminal of the battery...
  30. P

    How toasters works with the functions of elements in open loop system?

    1. Explain briefly an example of open loop system. At the same time, explain how this example works with the functions of the elements in the system. example is pop up toaster The Attempt at a Solution The pop up toaster can be set for the desireddarkness of the toastedbread. The setting of the...
  31. D

    Engineering Question about independent loop in a circuit

    I just had a question pertaining a circuit that consists of 3 loops in the attached picture: The textbook states that the loop inside with the 50[V] source is independent of the rest of the circuit, but I have a hard time rationalizing it. The only reason I feel it is the case is because the...
  32. C

    Examples of closed loop functions

    Can someone please give me a list of examples of closed loop functions, the only one I know is the equation for a circle y^2 + x^2 = r^2 Also are there any closed loop functions that aren't multi variable, i.e in the form y=f(x) and not z=f(x,y) Is there a way to tell that a function is...
  33. J

    Does Loop Quantum Cosmology Suggest a New Type of Multiverse?

    End of last year there was a paper "A loop quantum multiverse?" introducing a new paradigm for inhomogeneous loop quantum cosmology that could provide a resolution of the entropy problem of a new expanding universe. "Inhomogeneous space-times in loop quantum cosmology have come under better...
  34. marcus

    Quantum-reduced loop gravity (first quantize, then reduce)

    One of the papers on the 4th quarter MIP poll is one which introduced for the first time a new version of LQG which could be important. It directly gives rise to the corresponding LQC application to cosmology. Because instead of first reducing the classical system (say to Bianchi I, a simple...
  35. H

    Single phase inverter-current control loop

    Hello I am designing single phase inverter with TMS320LF2406 DSP. I created sinusoidal output voltage, and now i want to make regulation. While reading about regulation i found that it is recommended to use outer loop as voltage loop to generate Iref using PI controller, then this Iref...
  36. Z

    Outward force on current loop (Ampere's Force Law)

    Hi, I'm trying to calculate the outward force on a loop of wire carrying a current, radially from the center to the perimeter. I found the formula for the force between two parallel wires: http://hyperphysics.phy-astr.gsu.edu/hbase/magnetic/wirfor.html F/L = u0*I1*I2/(2*pi*r) And the...
  37. D

    Retarded potential of a wire loop

    Homework Statement This is the problem 10.10 in Griffiths' Introduction to Electrodynamics, 3e (See attached image) I am only concerned about finding the retarded vector potential \textbf{A} Homework Equations \textbf{A}(r',t) = \frac{\mu_{0}}{4\pi} \int \frac{...
  38. P

    Loop of pumped fluid slowly falling into black hole.

    You have this loop of water (or some other "incompressible" fluid) with a nuclear powered water pump that constantly pumps the water in a circle. This loop is slowly lowered near the event horizon of a black hole, let's even make it a super duper massive black hole to minimize tidal effects...
  39. S

    One loop integration evaluation

    Hey guys, I have a loop integration of the form below: -i\lambda\int_{-\infty}^{\infty}\frac{d^4k}{(2\pi)^4}\frac{i}{k^2-m^{2}} Where 'k' is the four vector: k=(E,\mathbf{p}) And so this integration could also be represented by expanding out the four vector...
  40. S

    What is a loop (in Feynman Diagrams)?

    Hey, I was wondering what exactly a loop is of this kind : I understand the initial & final four momentums to be the same and so there is no boundary on the possible allowed momentums in the loop. My professor said the loop is equal to (or can be modeled as) the self-interaction by...
  41. S

    Finding the loop gain of an oscillator

    Homework Statement Okay, so I know that I have to find the gain of the negative feedback part (1+ R2/R1). But then to find the transfer function of the bottom part of the oscillator, would the resistor and capacitor that are attached to the '+' terminal of the op amp be considered in...
  42. A

    Finding the area of one loop of the lemniscate

    Homework Statement Find the area of the region bounded by one loop of the lemniscate r2 = a2sin(2θ) with a > 0 using double integration. Homework Equations The Attempt at a Solution I was able to figure out the limits of integration for theta (0 to ∏/2), but what would my...
  43. L

    Control system - open loop transfer function and open loop gain

    control system -- open loop transfer function and open loop gain Is there any difference between open loop transfer function and open loop gain ?
  44. N

    Energy, Angular Momentum, Torque, solid ball rolling down loop track? help?

    Energy, Angular Momentum, Torque, solid ball rolling down loop track? help!? A solid brass ball of mass .280g will roll smoothly along a loop-the-loop track when released from rest along the straight section. The circular loop has radius R = 14.0 cm, and the ball has radius r<<R. (a) What is...
  45. Biosyn

    Comp Sci How to Use a While Loop with Arrays in C++?

    Homework Statement Homework Equations The Attempt at a Solution #include <iostream> #include <cstdlib> using namespace std; using std::cout; int main() { int sum=0; int Array[] = {1,2,3,4,42,5,6}; // int Array[] = {42,1,2,3}; // int Array[] = {12,-10,42,10}; // int...
  46. S

    Dropping a closed loop into a magbetic field

    Homework Statement The closed loop is vertical and the magnetic field is a north and south pole such that the looped end faces the magnetic poles. A multiple choice question answer stated that the closed loop will have a smaller acceleration than 10mls ^2 as it would experience an...
  47. N

    Recursion, How does it loop here?

    I skipped all of my lectures since I usually like to understand things on my own but I am regretting it for recursion. I don't know why but I am finding it quite unintuitive and confusing. I have an exam coming tomorrow so I have to make sure that I understand it correctly. I know that...
  48. R

    Energy, Force, and Inertia Problem. Ball down ramp to loop to loop

    Homework Statement A solid sphere of mass m and radius r rolls without slipping along the track shown below. It starts from rest with the lowest point of the sphere at height h above the bottom of the loop of radius R, much larger than r. (Consider up and to the right to be the positive...
  49. N

    Current loop rotating to give magnetic moment

    Homework Statement A uniform non-conducting ring of radius 0.816 cm and total charge 6.76 µC rotates with a constant angular speed of 1.73 rad/s around an axis perpendicular to the plane of the ring that passes through its center. What is the magnitude of the magnetic moment of the...
  50. Biosyn

    Comp Sci Master For Loops and If Statements with C++ Homework Help | GetCode.me

    Homework Statement Hello, the problem is in this video. It is displayed near the end starting from 6:19 onward. It's titled "Extra Credit" Homework Equations For Loops and If Statements? The Attempt at a Solution Here is my attempt at the problem: http://www.getcode.me/3sr0mzy7rz1cgrfu
Back
Top