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

    Pyhton data's structural size and loop efficiency

    While programming to find the largest prime factor for a composite number i came across a problem that if the number taken as input exceeds a certain limit, the loop time turns out to be a very long one and some times even resembling the time taken by an infinite loop.The method used for finding...
  2. M

    MATLAB Plotting Matrix in Matlab Loop - Mathias

    Hi, I have a matrix for instance as follow: A=[0.087 11.43 17.14 22.86 28.57 34.29 40.00 45.72 51.43 57.15 0.174 5.671 8.506 11.34 14.17 17.01 19.84 22.68 25.52 28.35 0.261 3.732 5.598 7.464 9.330 11.19 13.06 14.92 16.79 18.66 0.349 2.747...
  3. A

    MATLAB Matlab function errors while using loop

    Hi, Please assist, I write this MATLAB function and receive the error below function f=myfunn(z,x,K,L1,L2,phi) for c=1:3 f=z(c)-(x(2,c).*K(c).*L1)-(x(1,c).*phi(2,c).*L2)./phi(1,c); end function f=myfunn(z,x,K,L1,L2,phi) | Error: Function definitions are not permitted in...
  4. S

    Calculating Minimum Speed at Top of Vertical Loop

    Homework Statement A 330 kg roller coaster car sits on a horizontal track. Ahead of it is a vertical loop with radius of 6.85 m. The car is given an initial speed of 23.4 m/s and the car successfully traverses the loop. What is the maximum amount of energy taken away from the car by friction...
  5. S

    Fortran Fortran: inner loop dependence on outer loop

    Hello, I want to write an inner loop which takes values based on the variable values of the outer loop. For outer loop, m=1, Nmax and for inner loop, I want n to take values from 1 to Nmax-m. But I am not sure if I can directly specify n = 1, Nmax-m. Also I want to use Nmax-m value for one of...
  6. S

    Weight's effect on a current balance loop

    The problem is an experiment has been conducted where a solenoid current loop is matched to a current balance loop; the experiment was to determine the relationship between the current though the solenoid and the uniform magnetic field produced in the solenoid. one element of the experiment was...
  7. N

    Mathematica For loop in Mathematica doesn't work

    I have problem with for loop in Mathematica given in the notebook attached. It evaluates only first step and then shows problems and the kernel could not stop running. What could be the problem? What is the correct syntax?
  8. S

    Loop inside a solenoid, finding induced current

    Hey, The question concerns a basic solenoid with an oscillating current, we have a loop inside with a particular resistance and we want to determine the current induced in this particular loop. The question is in the image below: Right, well it tells us to determine the electromotive...
  9. S

    Use of Biot-Savart Law for Square Loop

    Hey, My question concerns the integration of the biot savart law of a differential magnetic field element to find the magnetic field at the center of a square loop. The question is part (c) (using info from (b)) of the image below: I want to check if what I did was right, but what I...
  10. marcus

    Reformulation of Loop gravity in progress, comment?

    The May 2012 "discrete symmetries" paper arXiv 1205.0733 signals a reformulation getting under way, I think. I'm curious to know how other people read this. There's been a pattern of the theory getting a major overhaul every 2 years or so. Many of us remember the 2008 reformulation, symbolized...
  11. D

    Circular motion-what is the radius of the loop de loop in meters

    Homework Statement Snoopy is flying his vintage warplane in a "loop de loop" path being chased by the Red Baron. His instruments tell him the plane is level (at the bottom of the loop) and traveling at 180 km/hr. He is sitting on a set of bathroom scales that him he weighs four times what he...
  12. D

    Circular motion- radius of the plane's vertical loop

    Homework Statement An 80-kg pilot flies a plane in a vertical loop. At the top of the loop, where the plane is completely upside-down for an instant, the pilot hangs freely in the seat and does not push against the seat belt. The airspeed indicator reads the 110 m/s. What is the radius of...
  13. A

    Why isn't the magnetic flux of a loop infinite?

    If B~1/r2, then if we have a simple loop, B near the inner edge of the loop will be infinite (or close to it). Why then, would our flux not be infinite? I also get infinity if I take ∫ ∇ X A *da =∫B*da =∫(closed)A*dl Since A ~1/r and r~0 at the limit of our surface integral. I know I am...
  14. F

    Magnetic Field square wire loop

    Homework Statement A current I is flowing in a square wire loop of side a. Find the approximate value of the magnetic field intensity magnitude at the point P, which is near to one of the corners in the plane of the square at the same d distance from the near two sides! (d<<a). Homework...
  15. S

    Stuck on a single loop circuit, two emfs and resistor

    Homework Statement ε[1]=12v internal resistance[1]=.016Ω ε[2]=12v internal resistance[2]=.012Ω some unknown resistance 'R' in a stand alone resistor. a) what value of 'R' will make the terminal-to-terminal potential difference of one of the batteries zero? b) which battery would it be...
  16. Y

    What Speed Does the Roller Coaster Need to Maintain at the Top of a 14m Loop?

    Homework Statement A roller coaster is moving past the top of a loop of diameter 14m. The Normal force (directed downwards) provided by the track at the top of the loop is equal to one-half the [B]weight[B] of the car. What is the speed of the coaster car at this point?Homework Equations Only...
  17. C

    Magnetic moment of a current loop.

    Hello, calculating the magnetic moment of a current loop is trivial, but I want to do it with the general formula \vec m = \frac{1}2 \int \vec r \times \vec J(\vec r) d^3\vec r The only thing which is stopping me is to find a good argument on why \frac{1}{2}\int \vec r d\vec r = \vec A where...
  18. E

    Loop Integration in Spinor Language

    Hi guys, i'm looking at one-loop calculations in terms of helicity spinor (basically a paper by Brandhuber, Travglini and others) language but i have no idea how to integrate them :) For instance \int FeynParam\int d^D L \frac{\langle a|L|b]^2}{(L^2-\Delta^2)^3} How would I do...
  19. A

    MATLAB Matlab for Loop of two changing variables

    Hi, Please I need your assistance on this MATLAB code. I will really appreciate it. R=0.492; Pw=0.3708; for r=1:5; for teta=10:10:360...
  20. O

    Can an Enclosed Superconducting Loop Generate Electromotive Force?

    Hi, If I take an enclosed superconducting wire loop, and apply a time dependent magnetic field in the space enclosed by the wire ( and therefore a time dependent magnetic flux) , this should induce electromotive force ( according to faraday's law). However any potential difference should not...
  21. H

    Basic magnetism on square loop question?

    A square loop carrying a current I creates its own magnetic field. Describe the forces on each side of the square loop due to its own field. What is the torque it experiences? My question is this. I know we can use bio savart. But for bio savart, B=uoI/2piR, what R do I use? suppose i have a...
  22. G

    Flux through loop around solenoid

    Homework Statement A simple loop of 5 cm radius encompasses the middle turns of a long coil. The coil has 2500-turns, is of length 1 m and radius 1 cm, and carries a current of 10 Amps. What is the magnetic flux through the single loop? Homework Equations B=μIN/L with L=1: B=μIN...
  23. B

    Magnetic Flux Through Wire Loop

    Homework Statement A wire loop with radius R is located a distance d from a long straight wire carrying a current I. Find the flux through the loop. Homework Equations B = \muI/(4\pi) Magnetic Field above wire \phi=B*da*cos\vartheta The Attempt at a Solution Somehow you have to...
  24. E

    Mathematica Mathematica Assumptions for integration [pertaining to loop corrections]

    Long story short I have an integral which is something like this: (in Mathematica code) Integrate[1/{(1 - b^2)*{((1 - y)*z + y)^2 + (1 - y)^2*(1 - z)^2} + 2*(b^2 + 1)*{(1 - y)*(1 - z)*((1 - y)*z + y)}}, {y, 0, 1} ] Written without assumptions. b is actually only in [0,1] and I think I...
  25. A

    Rotating Square Loop in Constant B-field

    [SOLVED] Rotating Square Loop in Constant B-field Homework Statement Homework Equations \epsilon = - \frac{d\Phi}{dt} \Phi = BAcos(\theta) = BAcos(\omegat) d\Phi = -BA\omegasin(\omegat) The Attempt at a Solution I'm trying to study for an exam and I've got this practice...
  26. C

    Troubleshooting Infinite Loops in C File I/O

    I am supposed to read from 2 text files containing numbers in ascending order, then output the all the numbers in ascending order to an output file, For some reason my output file is reaching an infinite loop it orders the numbers correctly but the last number reapeats forever. I am thinking it...
  27. marcus

    Loop Gravity as the Dynamics of Topological Defects

    There is a natural way to formulate Loop quantum geometry as the dynamics of line defects in a flat vacuum. Just under 2 months ago, I attended a 90 minute seminar talk on this at the UC Berkeley physics department. Unfortunately that talk is not online, but we do have an earlier talk given last...
  28. T

    One loop Fermi Constant running

    Hi I am attempting to calculate the mass of the W boson according to one loop energies using the equation, Mw2=(πα/GF√2)/sin2θw(1-Δr) where (Δr)top=(3GFMt2)/8√2π2tan2θw using values:- α=α(MZ)=(127.916)-1 GF=1.16634×10-5 sin2θw=0.23116 =>...
  29. S

    Lenz law wire and expanding loop

    Lenz law problem wire and expanding loop Homework Statement The loop has current radius R the red bar moves at velocity V. The distance the wire is from the loop is d and the top of the loop is length l Find the induced emf and the direction of the current in the loop. Homework Equations...
  30. U

    Find the EMF in the loop as a function of time.

    Homework Statement electromagnetic field Homework Equations E=hv The Attempt at a Solution I know that t is the variable and h1 and h2 I and I2 are considered given all we are doing is doing the algebra set up but not sure how to show this exactly.?
  31. U

    What is the direction of the induced current in the loop for each situation?

    Homework Statement THe problem is number 3 in the picture. Homework Equations The Attempt at a Solution Lens law changing magnetic flux through the loop not sure which way for each one little confused. Thank you
  32. A

    Calculating Induced Current in an Expanding Loop

    Homework Statement Imagine a pliable round metal loop that can expand or contract. In a region with a constant magnetic field B0 that is oriented perpendicular to the plane of the loop, suppose that the loop expands, with its radius growing with time as r = r0(1+at2). As the loop expands and...
  33. S

    Engineering Finding Current and Voltage in a multi loop circuits

    Homework Statement 1. Find the current in each resistor and voltage at point Vx Homework Equations Using Kirchoff's rule and system of equation I found currents but I am not quite sure how to calculate voltage at point Vx. I am pretty sure I got the currents right. Is it Vx =...
  34. A

    Induced Voltage created on a loop entering a magnetic field

    Homework Statement A 0.69m long and 0.69m wide loop is moved at a constant velocity of 0.81m/s from a region of zero magentic field into a perpendicular constant magnetic field of 0.21T. Calculate the magnitude of the induced voltage in the loop while it is entering the B-field Homework...
  35. N

    Nodal Analysis - KVL Loop question.

    Homework Statement I've obtained the node equations that's in the matrix for rows 1, 2, and 4. I got 3 as well but I'm not sure if my analysis was correct. http://img252.imageshack.us/img252/3151/nodeq.jpg The Attempt at a Solution http://img684.imageshack.us/img684/9803/dsc0010van.jpg So...
  36. W

    Magnetic field on the axis along the plane of loop

    Homework Statement A circular loop in the XY plane of radius R and with current I moving in the counterclockwise direction. Compute B at (L,0,0) for L >> R0. Homework Equations Biot–Savart law dB= μ0I/4∏ *(dl X r)/r^2 The Attempt at a Solution I know that the B on the axis...
  37. M

    Which describes the magnetic flux through a section of a loop?

    Homework Statement Which describes the magnetic flux through a section of a loop? A. It is a vector that is directed outward through the section. B. It is a vector that is directed inward through the section. C It is a vector that is tangent to the section. D. It is a scalar...
  38. A

    How Is Torque Calculated on a Current Loop in a Magnetic Field?

    1. A small current loop of area A=0.0007m2 and moment of inertia I=6.6e-07kgm2 carries a current i=0.0045A with its magnetic moment perpendicular to the Earth's magnetic field. The magnitude of the Earth's field is B=4.2e-05T. What is the magnitude of the net torque T on the loop? Homework...
  39. A

    The difference is the force on the loop.

    1. An infinite straight wire on the z-axis carries current I2=3.6A in the +z direction, upward. A rectangular loop is placed in the xz plane with its nearest side parallel to the wire a distance d=0.9m away. The loop has height (z-length) h=1.5m, width (x-length) w=1m, and carries a current...
  40. T

    Energy Dissipated in Loop (Magnetic Field)-

    Energy Dissipated in Loop (Magnetic Field)-- Please Help! Homework Statement What is the energy dissipated as a function of time in a circular loop of N turns of wire having a radius of r and a resistance of R if the plane of the loop is perpendicular to a magnetic field given by...
  41. N

    Magnitude of Torque on a current loop

    Homework Statement A small current loop of area A=0.0008m2 and moment of inertia I=6.9e-07kgm2 carries a current i=0.0039A with its magnetic moment perpendicular to the Earth's magnetic field. The magnitude of the Earth's field is B=4.2e-05T. a). What is the magnitude of the net torque T on...
  42. S

    Plotting 3D graphs for a script involving big loop

    I want to plot a 3D graph. A solid graph and a wireframe mesh graph. What are the different ways to do it in this script. The variables i want to be plotted in this script are 'pic' 'TSFC' 'NonFs'. Dont mind the working, everything is correct. The only matter of concern is the 3d graph and...
  43. K

    Find magnitude of magnetic field from loop

    Homework Statement A square loop, with sides of length L, carries current i. Find the magnitude of the magnetic field from the loop at the center of the loop, as a function of i and L. Homework Equations B=μ0/4∏∫i * dl X r^ /r^2 The Attempt at a Solution
  44. L

    A current-carrying circular loop placed next to a long straight wire

    Homework Statement A current-carrying circular loop of radius R is placed next to a long straight wire, as shown in the diagram below. The current in the straight wire points to the right and is of magnitude 3 A. see diagram...
  45. L

    Loop of wire is connected to the terminals of a battery

    Homework Statement A loop of wire is connected to the terminals of a battery. See Diagram: http://www.webassign.net/walker/22-35.gif The A terminal is of higher voltage, so the current travels clockwise from A to B through the loop. If you have the ability to send whatever current you like...
  46. L

    Magnetic Force on Various Sides of Spinning Loop?

    Magnetic Force on Various Sides of Spinning Loop?? Homework Statement A horizontal uniform magnetic field of magnitude 0.4 T is oriented at an angle of = 65° relative to a line perpendicular to plane of a vertical, rectangular loop, as indicated in the figure. The loop has a height of 8 cm...
  47. G

    MATLAB programming assignment (for loop)

    Homework Statement (see attached file) Homework Equations (see attached file) The Attempt at a Solution isbn=input('Enter 9 Letter ISBN number: ','s'); for i=1:1:length(isbn) (%indent)num=str2num(cat); (%indent)check=num*i %somewhere in...
  48. E

    What is the force exerted by a magnetic field on a rectangular loop of wire?

    Homework Statement A rectangular loop of wire with dimensions 2.32 by 7.91 and resistance 0.557 is being pulled to the right out of a region of uniform magnetic field. The magnetic field has magnitude 3.01 and is directed into the plane of the following figure . At the instant when the...
  49. phosgene

    Block moving on a frictionless loop

    Homework Statement A block moves on the frictionless slide shown in the diagram. What is the minimum height from which the block can be released if it is to complete the loop without leaving the surface of the slide? (Assume that the dimensions of the block are small compared to R, and that...
  50. T

    Finding the Force between a Straight Wire and a Triangular Current Loop

    Homework Statement A triangular loop of side length a carries a current I. If this loop is placed a distance d away from a very long straight wire carrying a current I', determine the force on the loop. See attachment for diagram. Homework Equations F=(\muII'/2\pir)L F=I'LB...
Back
Top