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

    Centripetal Motion problem -- A bead sliding around a horizontal loop

    To be honest I am a bit clueless first with how to interrupt this question I think the bead is going around a wall type thing where there is friction both in the up and X direction. Some hint to get some ideas running would be great
  2. Rubberduck2005

    Bead sliding on a Vertical Circular Loop versus in Free Fall

    I can evaluate the first beads motion easily A to B is -2Rj considering the point B as y=0 the motion of the bead will be -gt^2/2+2R=0 which implies t=2√(R/G) , this is ok but what I am struggling with is A to C I can see that the angle between the beads weight and it's negative normal force...
  3. P

    I Energetic argument for the tension in a current loop

    The energy stored in a current loop equals ##\frac{LI^2}{2}##. From a dimensional argument, it follows that the inductance grows with the size of the loop. This would mean that, if we assume the current stays constant, enlarging the loop would require external positive work, so, the force...
  4. mastermechanic

    How to implement PID control in Arduino w/o using loop function?

    Last week I encountered a problem in my graduate project. The project was about designing an autonomous and mobile robot that picks up 9 glass tiles from a stack point and place them into a 3x3 matrix with minimum tolerance. I am using a DC motor with an infinite turn potentiometer for closed...
  5. M

    Question about a Python for loop

    Hi All I'm learning python and have never seen a for loop positioned like this: integers = [4, 5, 7] strings = [str(integer) for integer in integers] I've only ever seen for loops positioned at the beginning of lines. Is this usual? How can I know when this is okay? I think I would have tried...
  6. K

    Can You Make a Frictionless Loop Turn?

    Suppose we are give a homogenous hollow cylinder or "normal" dimensions (for example 3" inside dia., 4" outside dia., 5" high". The composition is any non-exotic, non-magnetic, solid material. Is there any way to cause it to rotate about its vertical axis? Whatever the material is, any...
  7. MNaydenov

    Mathematica Loop integrals using Package-X 2.0 in Wolfram Mathematica

    Hello everyone, I have trouble installing Package-X 2.0 to Wolfram Mathematica. It says that the package should be available at https://packagex.hepforge.org but this page does not open. I tried everything I could to install and load this package but it was all unsuccessful. It seems as the...
  8. Eclair_de_XII

    LaTeX How to loop through reading .txt files while conditioning on line no.?

    \newcommand{\printNum}[2]{% #1 #2% } \newread\readEng \newread\readEsp \newread\readLineNo \newcount\myLineCount \myLineCount=0 \newcommand{\printNumRow}{\loop\global\advance\myLineCount by 1\read\readEng to \Eng \read\readEsp to \Esp \printNum{\Eng}{\Esp}\ifnum\myLineCount=\linenum...
  9. B

    Induced EMF in a small square loop of wire at center of an AC Circuit

    I used the voltage of the power supply and resistance to solve for the current in the larger circuit (20V/5ohms=4 amps). I am not sure if the equation listed above is the correct one I should be using, but I tried it using the following numbers. For omega, I used 2*pi*frequency. N should...
  10. F

    Engineering What is the Open Loop Gain of an Amplifier?

    I’m totally lost and struggling to understand my lecture notes. Can somebody point me in the right direction?
  11. M

    Engineering Questions about the workings of a phase locked loop

    Hi, I had one or two questions about the operation of a PLL, which refer to the diagrams below - a control representation of the system and a diagram of the low pass filter circuit. Questions: 1) What is the point of having another (low-pass) filter ## G_f (s) ## for ## V_o ## after...
  12. JD_PM

    Loop Feynman diagram contributions to correlation functions

    My understanding of the n-correlation function is \begin{equation*} \langle \phi(x_1) \phi(x_2) ... \phi(x_n)\rangle = i \Delta_F (x_1-x_2-...-x_n) \end{equation*} Where ##\Delta_F## is known as the Feynman propagator (in Mathematics is better known as Green's function). Let us analyze...
  13. M

    Showing that this identity involving the Gamma function is true

    My attempt at this: From the general result $$\int \frac{d^Dl}{(2\pi)^D} \frac{1}{(l^2+m^2)^n} = \frac{im^{D-2n}}{(4\pi)^{D/2}} \frac{\Gamma(n-D/2)}{\Gamma(n)},$$ we get by setting ##D=4##, ##n=1##, ##m^2=-\sigma^2## $$-\frac{\lambda^4}{M^4}U_S \int\frac{d^4k}{(2\pi)^4} \frac{1}{k^2-\sigma^2} =...
  14. M

    Magnetic field of a current loop

    This should be pretty straightforward and my take gives B = 0.000193*T for a) and B = 0.00000063 T for b). Or have I misunderstood something?
  15. F

    Questions about the for loop, iterable, iterator in Python

    Hello, I understand that a ##for## loop is intended to repeat the same code a finite and specified number of time. The loop syntax is for i in iterable: statement(s) for = keyword i = counter variable iterable = any iterable (list, tuple, dictionary, range()) statements = body of the...
  16. davidfur

    Fortran Parallel DO loop with OpenMP (fortran)

    Hey guys, I've started to read some OpenMP programming and now I'm trying to parallelize small part of a fortran code. The first thing I would like to do is to parallelize the innermost DO loop. It loops through the number of particles (na) and calculates the distance between some point in 3D...
  17. cookiemnstr510510

    Matlab for loop indexing confusion

    The test case for the block of code below is: y0=10, f=@(t,y) -0.5*y, [t,y]=euler_method_attempt(f,0,5,y0,10) This code below works and is the correct answer, but I am confused on some parts of it. When indexing the for loop it seems as if the first output for "y" would be y(2), not y(1). And...
  18. Marilyn67

    I Unravelling the Mysteries of the Kerr Black Hole Ergosphere

    I have a problem understanding what is going on in the region called the ergosphere of a "fast" Kerr black hole. - Relativity teaches us that no frame of reference can have relative displacements greater than the speed of light, ok. - The ergosphere of a fast Kerr black hole can contain light...
  19. J

    Matlab How to plot values from a loop

    %Debeye theory Heat Capacity of Copper %Garcia Problem 10.16 %Find molar heat capacity from 0-1083K (melting point of Cu) k = 1.38064852e-23; %Boltzmann's constant N = 6.02214e23; %Avagadro's number (atoms per mol) T = 0:1083 ; %Initialize Temp at 0K-1083K theta = 309; %Debeye temp of Cu (K)...
  20. Lutz-F

    B Theory of Loop Quantum Gravity

    From the german Version of Carlo Rovellis book "La realtà non è come ci appare. La struttura elementare delle cose" I have learned about the theory of Loop Quantum Gravity that space and time arise through the interactions of gravitational quanta, the space quanta have discrete volume spectra...
  21. greg_rack

    Torque on a current loop caused by a magnetic field

    Okay, so, the magnetic field lying(parallel) to the plane of the coil is confusing me quite a bit. Usually, in this kind of problem, we have a magnetic field directed perpendicularly to the plane. Considering this orientation of the field, wouldn't the torque on this sort of "elementary brush...
  22. Jason-Li

    Why Does Increasing G in a Control Loop Cause Vo/Vi to Approach Unity?

    Hi all Physics Forum User, I am again coming to you to ask for help. For the above question I can't make sense of how a larger G will cause Vo/Vi to approach 1. For this I'll call Vo=V and Vi=I As can be seen from the control loop B = A*H and V = B*K hence V = A*H*K Also A = I - C and...
  23. WhiteWolf98

    MATLAB How to make a while loop stop when reaching a certain value

    m_1 = 1; C_p1 = 2219; T_1in = 100 + 273.15; T_1out = 75 + 273.15; Q_1 = (m_1)*C_p1*(T_1in-T_1out); while Q_1 ~= 30000 T_1outnew = T_1out + 0.1; Q_1 = (m_1)*C_p1*(T_1in-T_1outnew); T_1out = T_1outnew; end T_1outnew keeps increasing, but the code never stops; and naturally, Q...
  24. M

    Closing the writing loop, again with thanks

    It's only a small PF shout out for my third novel, Handwavium, because it is more techno thriller than pure sci-fi story, so it didn't ask much from the collective brainpower of the forums. Still @Vanadium 50 and @stefan r gave their assists with gravitational wave triangulation, for which I...
  25. cestlavie

    Length of sides of a wire loop in a uniform magnetic field

    If ##\tau= 0.0727, N=60, i=1.3, B=1.0,## and ##\theta=15##, I tried the following calculation: ##\tau=NIABsin\theta## ##\tau=NIs^2Bsin\theta## ##s^2=\frac {\tau} {NIBsin\theta}=\frac {.0727} {60*1.3*1*sin(15)}=0.0632 m=6.32 cm## The answer is probably right in front of me, but I don't know what...
  26. The black vegetable

    A How to find the gamma function for a fermion vacuum energy calculation?

    Following the method by Peskin and Shroesder 11.4 Trying to calculate the vacuum energy of a fermion. If my method is correct so far the next step is to find gamma function , the formula I have for gamma fuctions doesn't match this equation. Can anyone help with the next step? Starting with the...
  27. greg_rack

    Applying Kirchhoff's laws for a loop analysis

    For this one circuit, I've applied Kirchhoff's laws as following: $$\left\{\begin{matrix} V-6\Omega I_{6}-24V-2\Omega I_{2}=0\\ 24V-6\Omega I_{6}-12V-24V=0\\ I_{2}+I_{6}=6A \end{matrix}\right.$$ but the values I get for ##I## and ##V## aren't correct... what's wrong?
  28. J

    Understanding Loop Currents: Why is I3 Negative?

    Hello, In the following problem, when finding the equation for I2 I don’t understand why I3 is negative. Although I2 and I3 are going in different directions (clockwise and counterclockwise), at that ohm they are both going from left to right. When finding the equation of I1, I1 goes from left...
  29. M

    Engineering Closed Loop Stability Criterion: Find the values for closed loop stability

    Hi, I was just working through a closed loop stability problem in Control Theory and I don't really understand how the answer has arrived at the solution so quickly. Problem: We are working with the closed loop transfer function: $$ P(s) = \frac{K(s) G(s)}{1+K(s)G(s)} $$, where $$ G(s) =...
  30. S

    Current in a current-carrying loop experiencing no torque

    Disclaimer: The solution to this question has already been posted by my instructor. I made this post to understand why my solution is wrong or if the instructor is wrong, since their explanation does not make sense to me. My reasoning: Using the fact that the magnetic torque on a...
  31. saadhusayn

    A Two loop Feynman diagram with quartic vertex

    I am trying to calculate the effective potential of two D0 branes scattering in Matrix theory and verify the coefficients in this paper: K. Becker and M. Becker, "A two-loop test of M(atrix) theory", Nucl. Phys. B 506 (1997) 48-60, arXiv:hep-th/9705091. The fields are expanded about a constant...
  32. P

    Calculating the Force and Torque on a current loop

    ##\vec \tau = \vec \mu \times \vec B -eq1## ## F = I \vec l \times \vec B -eq2 ## The forces i have indicated The magnetic moment is coming out of the page. I am only attempting only the part (a) as of now a. The force calculations are F1 = 1.4*0.22*1.5 = 0.462 +X direction F2 = 1.4*0.22*1.5...
  33. ohwilleke

    I Trouble for Loop Quantum Gravity?

    A new preprint establishes that almost all models implementing loop quantum gravity violate the principle of general covariance, and can only satisfy a more limited condition. Is this the huge problem for loop quantum gravity theory that it appears to be? Or is the less strict condition that can...
  34. F

    Work done on a moving square wire loop in a B-field

    There’s a current i in the loop in the figure. The Ampere’s force iLB on a wire of length L exerts on charges in the wire but it does no work on the charges. The charges would go in circular motion if there were no wire. Then the wire exerts exactly iLB on those charges to keep the charges...
  35. I

    I Why is 2.5 times the radius the minimum height needed to do a loop?

    The height can be determined by conservation of energy (ignoring all friction). The mechanical energy when the car is at rest, equals the mechanical energy when the car is in the middle of the loop (at the top of the loop): \begin{equation} E_{0} = E_{loop} \\ mgh_0 = \frac{1}{2}mv^2+mgh_{loop}...
  36. G

    How to get the magnetic moment for this loop?

    About this figure, the current in the opposite wires are parallel (and not anti-parallel). So, for instance for the first option the torque is zero; but I wanted to know what is the magnetic moment of this loop. Since I rely only on formula I've have no idea how to compute for this one.
  37. Kharrid

    Induced EMF in a moving Loop Conductor

    I am having trouble figuring out if the circular loop has an induced current. One explanation is ∫ E ds = -d Φ / dt. Since flux = B ⋅ A, a change in the magnetic field would require a change in the magnetic field, a change in the area, or change in direction of either vector. Since none of...
  38. Leo Liu

    Torque on a circular current loop

    Can anyone please tell me why the torque on a circular current loop can be calculated by the equation below? In other words, what is the intuition for the formula? Thank you. (I modified my question to a particular case) $$ \vec{\tau} = I \vec{A} \times \vec{B} $$
  39. A

    Comp Sci Do-while loop-> exit not working (making a crossword puzzle)

    Hello! My homework is making a crossword. I write a code like this: do{ //code printf("Please enter the coordinate and the word: \n"); scanf(" %c%d %s",&row2,&column2,word2); if(row2=='E' && word2=="xit") exit(0); //code }while(count2!=10); But this is...
  40. M

    Closing the writing loop, with thanks

    I haven't been on PF that long, and I mostly post in the Science Fiction section, but I have noticed in the "Writing and World Building" forum that few of us loop back after asking for help to let people know, "My novel is done". So, just to let you know, my novel is done and is live in the...
  41. Bilbo B

    Magnetic field affecting a circular loop

    If the magnetic field is constant then no change in flux will bring no induced emf nor any induced current. With the loop is in rest position the external magnetic field will exert a force but to calculate that force with the help of magnetic field isn't obvious. If this were a charged loop, the...
  42. U

    Understanding the Minimum Speed to Keep Carriage on Tracks in a Loop

    I recognise that the normal force must alwayss act towards the centre of the circle loop, as the rail always has to be exertign a pushing force on the car/carriage in order for it to follow the trajectoryof the loop. However , I cannot understand why, the reaction force has to be greater than...
  43. K

    I Effect of inserting an analyzer loop in the EPR experiment

    Given an EPR experiment such as the Alain Aspect 1982 test of non-locality using photons; if you modified the experiment so that the entangled photons first go through a analyzer loop (polarizer + inverse polarizer) before going to the polarizers in the experiment would you still see a non-local...
  44. P

    A Parallel transport of a 1-form aound a closed loop

    Good day all. Since the gradient theorem, also known as the fundamental theorem of calculus for line integrals, says that a line integral through a gradient field can be evaluated by evaluating the original scalar field at the endpoints of the curve. Then If we form the Gradient vector field...
  45. W

    I Understanding Loop Quantum Cosmology

    As I understand it there have been different attempts to use LQG to make a theory of cosmology. The first one being done by Martin Bojowald and then later one being performed by Ashtekar, Pawloski and Singh. there is a description of what they did that was different but as a non cosmologist I...
  46. P

    Magnetic field Calculation of a Square Wire Loop (with a changed segment)

    I tried to solve the above i have one confusion here. I have marked the areas as shown B2 = B4 = 0; B1 , B5 Out of Page ; B3, B6 Into the Page. B1 and B5 Calculation Now main doubt is regarding the B field of the finite wire let us say 1. I took the derivation of the infinite wire as below from...
  47. Alefan_

    Average current around a magnetic loop that changes its shape

    To find out what the induced loop current was i used the formula: V=R×I To find out what the value of V was i used the formula that links electromotive force (fem) to angular speed: Fem=ω×B×A The only thing that's missing is the loops area but considering that it's a semicircle and that the...
  48. A

    Induced/eddy current cancelation in a loop

    Hi, I have a theoretical problem, I am wondering would it be possible to cancel the otherwise induced currents within a planar sheet/foil conductor. you can see in the image I have a flattened conducting sheet which in the middle is split up in individual smaller conductors (for the sake of...
Back
Top