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

    Comp Sci Fortran:store loop value in array

    Homework Statement My program calculates the value of a function. Then it prints them on the screen. This is the part: do while(x<=b) variablesvalues(1)=x x=x+delta call recog_variables (func, variables) answer=evaluate(variablesvalues) print*, answer end do What I need to do now is to save...
  2. V

    Electric field above a square loop

    Homework Statement Problem 2.4 from Griffiths Intro to Electro[/B] Find the electric field a height z above the centre of a square loop with sides a and linear charge density λ. height is given to be z and sides given to be a, ∴ distance from origin to side is given by a/2 Homework Equations...
  3. K

    Electric Dipole Radiation from a Spinning Current Loop

    Homework Statement Hi everyone, My problem is fairly simple: We have a circular current loop enclosing area A, and with a constant current I. The loop is rotating about its diameter at a constant angular frequency \omega. All we need to do is find the electric dipole, and magnetic dipole...
  4. N

    Magnetic field at the center of a loop

    Homework Statement A conductor consists of a circular loop of radius R = 14.4 cm and two long, straight sections as shown in the figure. The wire lies in the plane of the paper and carries a current I = 1.60 A. Find the magnetic field at the center of the loop. Homework Equations...
  5. A

    Why are larger transformers more efficient than smaller ones?

    Homework Statement Transformer efficiency loss Homework Equations Larger transformers are more efficient than smaller The Attempt at a Solution I understand the basics of energy loss through heat etc but i don't understand why it would be different for the sizes of transformers. Is it to do...
  6. Krack

    Shielding & ground loop for audio

    I have a 3 conductor wire that are all wrapped in a foil shield with wire conductor, for a total of 4 wires. I am connecting the 3 inside wires to audio left, right, and ground. This is an unbalanced setup, right? Where/how do I connect the shielding? Do I connect both sides (i think no)...
  7. A

    Vector Calculus: Air flowing through loop of straight lines

    Homework Statement Air is flowing with a speed v in the direction (-1, -1, 1,) calculate the volume of air flowing through the loop consisting of straight lines joining (in order i presume) (1,1,0) (1,0,0) (0,0,0) (0,1,1) (1,1,0) Homework EquationsThe Attempt at a Solution I assume you have to...
  8. ognik

    Magnetic moment of current loop integral

    The question states: The calculation of the magnetic moment of a current loop leads to the line integral ∮ r x dr I am puzzled - shouldn't this be ∮ r x dl where r is the radius of the loop and dl is the small change along the loop? (I think dr would be in the same direction as r, so no cross...
  9. S

    Why Can't Conservation of Energy Be Used to Solve the Loop Problem in Physics?

    Homework Statement Bob starts at rest from the top of a frictionless ramp. At the bottom of the ramp, he enters a frictionless circular loop. The total mass of the child and the cart he sits in his m. What must the height of the ramp be in order for the cart to successfully traverse the loop...
  10. W

    Current Loop Generating a Magnetic Field

    I'm trying to understand how to calculate the strength of the magnetic field generated by a current loop. What I know so far is: When a current moves around a loop of wire it generates a magnetic field which looks a bit like that of a solenoid, only not so concentrated through the center of...
  11. D

    Reaction force at the top of a rollercoaster loop

    I understand that in a rollercoaster loop, two forces combine to make the centripetal force required to keep the cart moving in a circular path - the cart's weight, and the reaction force of the track against the cart (except in the special case where the cart's weight alone is sufficient for...
  12. T

    Biot-Savart non-textbook Equation -- B at point above a loop but off-axis

    I read everywhere about the formulas for calculating B at a point from a length of straight wire, or at a point from the centre of a closed loop. But what about at a point over a closed loop that wasn't the centre? Is there a simple calculation for that? Thanks
  13. Coffee_

    Force on a shrinking circular loop in a constant B field

    1. A conducting loop is shrinking in a constant ##\vec{B}##-field that is perpendicular to the loop-axis. The radius of the loop is given by ##r(t)=r_{0}e^{-at}##. The resistance in the loop is ##R(t)=2 \pi \rho r(t)##. What force is needed to keep the loop shrinking like this?2. Faraday's law...
  14. Coffee_

    The solid angle equation for the magnetic field of a loop

    Background: Using Biot-Savart law we proved that for a closed loop with current ##I##, the magnetic field at a point P was equal to ##\vec{B}=-\frac{\mu_{0} I \nabla{\Omega}}{4 \pi}## where ##\Omega(x,y,z)## is a function of the position of P that represents the solid angle at which the loop is...
  15. Ace10

    One Loop corrections in ee--->ee scattering in QED

    Homework Statement First of all, Happy New Year! I have to solve the following exercise (xmas gift :P) and some things are a bit vague..Here is it: For the ee--->ee scattering process, draw all amputated and connected graphs that would contribute. The hint is that one should find 10 different...
  16. Prashasti

    Kirchhoff's Loop Rule Problem.

    Homework Statement Actually, the main question is to find out the potential difference between the points 'A' and 'D'. The cell with emf 'E' has not been shown in the main question, but I have assumed it to be connected between 'A' and 'D'. Each resistor is of 1 Ohm. 2. The attempt at a...
  17. Hijaz Aslam

    Force on a circular loop due to hypothetical magnetic field.

    Homework Statement A hypothetical magnetic field existing in a region is given by ##\vec{B}=B_o\vec{e}_r##, where ##\vec{e}_r## denotes the unit vector along the radial direction. A circular loop of radius a, carrying a current ##i##, is placed with its plane parallel to the X-Y plane and the...
  18. marcus

    How does the projective LQG approach shift the traditional formulation of LQG?

    A major change is happening in the way LQG is formulated. Suzanne Lanery gave a seminar about this 5 days ago (10 Dec) at Perimeter, and today she gave a similar talk at Nijmegen (Renate Loll's seminar). It's evident there is a lot of interest in this new development, which is based on the 11...
  19. K

    Design a Voltage Feedback Loop w/ PID Controller

    Hi Can anybody tell me where to put a PID controller in the picture below to design a voltage feedbaxk loop? Thanks
  20. D

    Problem 2.4 Griffiths E&M 3rd ed -- E-field above a square loop

    Homework Statement The problem states, "Find the electric field a distance z above the center of a square loop (sides of length a) carrying a uniform line charge λ. " The hint says to use the result of example 2.1. Example 2.1 is a similar problem, but instead of a square loop you are asked...
  21. SalfordPhysics

    Comp Sci Fortran90: DO loop for sequence of numbers

    Homework Statement A program finds the area under the Gaussian Distribution Curve between ±σ using Simpsons Rule. Modify the program to investigate the effect of the number of strips. Do this by using a DO loop in the main program for the following sequence of number of strips (n); n-2, n-4...
  22. Mr. Rho

    Radiation in the far field for a current carrying loop

    Hi people, I have a problem with some integral here. I have a loop of radius a, with a current I = Ioe-iωt' and trying to calculate the radiating fields in the far zone, my procedement is: Current density: J(r',t') = Ioδ(r'-a)δ(θ'-π/2)e-iωt'/2πa2 φ (φ direction) Here t' = t - |r-r'|/c...
  23. S

    Centripetal Acceleration at top of Loop

    Homework Statement A roller coaster is on a track that forms a circular loop in the vertical plane. If the car is to just maintain contact at the top of the loop, what is the minimum value for its centripetal acceleration at this point? A) 2g downward B) g downward C) 2g upward D) g upward E)...
  24. teroenza

    Mathematica Mathematica: Getting part of a list, lithin a loop.

    When I use the code directly below, it works (indicated by the "Out:..."). tmp2 = Flatten[{33, {1, 2 + j, 6}, 55}];(*Out:{33,1,2+j,6,55} *) tmp2[[4]]; (*Out: 6 *) But when I use it inside a loop, it acts like the tmp2 list is not the correct size: For[j = 0, j <= 5, j++, tmp2 = Flatten[{33...
  25. D

    What is the impact of quantum loop gravity on the standard model?

    How much of the standard model do we have to change/forget in order for quantum loop gravity to work?
  26. bibo_dvd

    How Do You Calculate Torque on a Triangular Loop in a Magnetic Field?

    hello guys iam doing my homework in magnetic fields course and i found this problem i solved (a) and (b) by using F=I L x B and the total force on the triangular loop would be zero but in (c) i tried a lot to find the torque on the loop but i couldn't get the same result so please help me...
  27. evinda

    MHB Creating a Loop Version of HEAPIFY Algorithm

    Hi! (Wave) Given the following algorithm: HEAPIFY(A,i) l=LEFT(i); r=RIGHT(i) largest=i; if (l<=size(A) && A[l]>A[largest]) largest=l; if (r<=size(A) && A[r]>A[largest]) largest=r; if (largest!=i) swap(A[i], A[largest]) HEAPIFY(A,largest) I want to...
  28. D

    Maximum torque for current loop

    Homework Statement A current loops is oriented in three different positions relative to a uniform magnetic field. In position 1, the plane of the loop is perpendicular to the field lines. In position 2 and 3, the plane of the loop is parallel to the field as shown. The torque on the loop is...
  29. G

    Difference between a spinning sphere and rolling one

    Consider this: We have a sphere rolling down a slant, released from some height h with null velocity. At the end of the slant its potential energy will have been fully converted to kinetic energy, part translational and part rotational. Now consider this: at the end of the slant the ball enters...
  30. R

    Loop Quantum Gravity and the Concept of the Universe as a Co

    Disclaimer: I'm just an amateur enthusiast who is a programmer during the day I suppose everyone who takes an interest in physics who doesn't have the mathematical tools to further their enquiries end up writing posts like mine, and that at the very least it's nice to see where the ideas reside...
  31. E

    How Fast Must a Car Go to Clear a 12m Loop and What Are the Max G-Forces?

    1. So the loop is known to be 12m in diameter (6m radius). Assume the car weighs 1250kg - how fast must the car go to clear the loop, and what will be its max G-forces endured? This was the question, which I have broken into 3 sections: a) Velocity at top of loop (done) b) Velocity at start of...
  32. S

    Electromagnetic field profile around a closed loop

    Is there a way to determine the profile of the field around a charged closed loop - particularly on the direction normal to the plane of the loop, both front and back? For generic values of V, I, B, H, etc., and any dimensions of the loop, any particular formulae possible to obtain? Thank you...
  33. S

    Calculate a vector potential of a simple loop

    Homework Statement Calculate the vector potential of a loop with current ##I##, raidus ##a##. Calculate it for anywhere in space and use approximation where ##r>>a##. Homework Equations ##\vec A=\frac{\mu _0I}{4\pi }\oint\frac{d\vec l}{|\vec r-\vec{r(l)}|}## The Attempt at a Solution Ok...
  34. Feodalherren

    Faraday's Law - induced emf of a rotating loop

    Homework Statement Consider the loop in the figure below. What is the maximum induced emf in each of the following cases if A = 600 cm2, ω = 31.0 rad/s, and B = 0.490 T? Rotating about x,y,z? Homework Equations Faraday's law The Attempt at a Solution This should be relatively easy since the...
  35. J

    Closed Loop Contour: Finding Threshold W Values

    I have a multivariable function, z = f(x, y, w), represented by a surface plot in 3D (z versus xy) for each value of w. As w varies, the function z varies (goes up and down and changes shape) over a given rectangular xy region. As z varies with w, contour lines with given constant values of z...
  36. Feodalherren

    Magnetic Flux & Current in a Dropped Magnet & Wire Loop

    Homework Statement A bar magnet is held above the center of a wire loop lying in the horizontal plane, as shown in the figure below. The south end of the magnet is toward the loop. After the magnet is dropped, what is true of the current in the resistor as viewed from above? (Select all that...
  37. A

    Moving magnetic dipole into current loop

    Homework Statement A magnetic dipole m is moved from infinitely far away to a point on the axis of a fixed, perfectly conducting (zero resistance) circular loop of radius a and self-inductance L. In its final position the dipole is oriented along the axis of the loop and is a distance z from...
  38. I

    C/C++ Solving the Loop Puzzle: Shifting Old Scores to New Scores

    Write a loop that sets newScores to oldScores shifted once left, with element 0 copied to the end. Ex: If oldScores = {10, 20, 30, 40}, then newScores = {20, 30, 40, 10}. Sample program: #include <iostream> #include <vector> using namespace std; int main() { const int SCORES_SIZE = 4...
  39. M

    Biot-Savart and a Rectangular Loop

    Homework Statement Consider the figure on the right. Wire 1 is oriented along the y-axis and carries a current I1. A rectangular loop located to the right of the wire in the xy-plane carries a current I2. Find the magnetic force exerted by wire 1 on the top wire of length b in the loop...
  40. P

    Magnetic interaction of wire and rectangular loop

    Hi. In this video: he ignores the magnetic field from current 2(I2). Could anyone give me a good explanation why?
  41. C

    Will cars with different mass make a loop in a tunnel with same given velocity?

    me and my colleague watched Mercedes Benz commercial where its sports car accelerated, went in a tunnel, and made a complete loop around the tunnel by going up against the wall. Now, the debate was on whether a car can manage to make a loop in a same tunnel with same given velocity entering the...
  42. C

    How to evaluate a triangular fermion loop

    Say I have a scalar field which decays into to a fermion - anti fermion pair which then interact in a closed loop to produce two photons. How would I evaluate this? Can I just follow the loop backwards from any of the two photon vertices and just write vertex factor, propogator, vertex factor...
  43. I

    C/C++ "Understanding the C++ For Loop Variable [i]"

    ok so i realized my problem with c++ is that i don't really understand for loops. well it's not exactly the loop itself but i don't understand the loop variable [i]. what is for EXACTLY? why is it needed? why can't you just use the other variable you are using? why does this extra variable need...
  44. Z

    Open loop vs Closed loop Transfer Functions

    Okay, I have a simple plant which is 1/s*(s+1) Two poles on 0 and -1 and no zeros. This is the case for open loop. But when I close the loop with unity feedback and add a K gain, I end up with following transfer function; K/s^2 + s + K So, clearly the poles are now at somewhere else. However...
  45. M

    Simple Kirchoff's loop problem

    Homework Statement Find the currents going through each resistor. Homework Equations V=IR The Attempt at a Solution [/B] I have the problem worked out and I can't find any errors in my work. The issue is that my professor has: I1=-.0843 I2=.086 I3=.0017 However my physics professor is...
  46. I

    MHB BASIC: Blink LED w/ Push Button Using DO...WHILE Loop

    use the DO...WHILE...LOOP statement to blink an LED at a rate of 2 times a second as long as a push button is pressed. If the push button is not being pressed, the program should wait until the button is pressed and held before blinking the LED. To solve this problem, the DO...WHILE...LOOP will...
  47. 2

    Tests of loop quantum gravity?

    I am doing a project of theories of gravity, and am having some trouble understanding whether loop quantum gravity is testable or not. I had some questions which I cannot seem to find the answers to: 1. Is it theoretically possible to probe distances of 10^{-35} or would the concentration of...
  48. I

    MHB Continuously Bid with While Loop - Stop at 'n' | Sample Program

    Write an expression that continues to bid until the user enters 'n'. Sample program: #include <iostream> using namespace std; int main() { char keepGoing = '-'; int nextBid = 0; srand(5); while (<STUDENT CODE>) { nextBid = nextBid + (rand()%10 + 1); cout << "I'll bid...
  49. R

    Calculating EMF Induced by Moving Rectangular Loop

    Homework Statement A rectangular loop of wire, of sides 5 and 3 cm moves away from a a long straight wire at 4ms-1 carrying a current of 2 amps. What is the EMF induced in the moving loop, when the near side of the loop is 3cm away from the wire? Homework Equations B = μ0I/2πr EMF = -dΦ/dt...
  50. I

    C/C++ C++ Loop Variable: What & Why?

    what is the purpose of a loop variable (i)? how is it useful?
Back
Top