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

    C/C++ Infinite loop problem C++ for char instead of int

    I need some help in optimizing a code with a prompt yes/no...My problem is that if I mistype within the loop for r some character (let's say I'm missing the number 8 on the keyboard for u) the program gets into an infinite loop. Do you know some way that I could solve this problem? Like printing...
  2. sergiokapone

    Wire loop in magnetic field of the long magnet

    Homework Statement The wire loop ##ABCD## is in a magnetic field of the long thin rod magnet with a magnetic moment per unit volume of ##\mathfrak{M}_0## and a cross section ##S##. The north pole of this magnet is in the center of the loop, and the magnet is perpendicular to the plane of the...
  3. H

    Prove that the torque of any current loop is m X B

    Homework Statement Problem 6.2 of Griffith's "Introduction to Electrodynamics": Starting from the Lorentz force law ##\vec F=\int I (d\vec l \times \vec B)##, show that the torque on any steady current distribution (not just a square loop) in a uniform field ##\vec B## is ##\vec m\times \vec...
  4. Robsta

    Square wire loop moving in a static B field.

    Homework Statement [/B] 3. A square loop of area a 2 is formed from a single turn of thin wire of resistance R. The loop is aligned with two sides parallel to an infinite straight thin cable, with its closest side a distance r away, and is given a velocity v in a direction perpendicular to the...
  5. W

    Technical question about loop corrections

    Does anyone know a simple explanation for the following statement: Gauge invariance ⇒ $Πμνϒϒ(0) = ΠμνϒZ(0) = 0$ Where ΠVV' is the V to V' one loop correction, ϒ is the photon field and Z is the Z-boson field. The argument of Π is the incoming momentum q2 = 0
  6. X

    Current requires a closed loop to flow in DC, not AC?

    It is my general understanding that according to KCL, current requires a closed loop to flow in DC. However, this is apparently not true in AC; current doesn't needa closed loop to flow. I have drawn a circuit below which causes confusion: C1 is a charge capacitor, R1 is a resistor, I1 an...
  7. Mattman182

    Peak current flowing in a circular metal loop?

    Homework Statement Homework Equations I have some equations relating B to I but I don't really know if they are useful The Attempt at a Solution I actually don't even know where to begin on this, my notes are confusing and vague :(
  8. J

    A formula to calculate speed on loop de loop

    I am trying to calculate the average speed of a car while traveling around a loop de loop in m/s and km/h can anybody help? Thanks
  9. M

    Torque by magnetic field on a current carrying wire loop ?

    as u know torque is given by NI(A X B) where N and I are number of loop turns and current magnitude respectively, A is area in vector and B is magnetic field in vector. regarding the direction of area : what normal to take as a direction, is at that which makes acute angle with magnetic field...
  10. A

    Contracting Loop in a Magnetic Field

    Homework Statement An elastic circular loop in the plane of the paper lies in a 0.81 T magnetic field pointing into the paper. If the loop's diameter changes from 19 cm to 6.8 cm in 0.45 s, a. what is the magnitude of the average induced emf? b. If the loop's resistance is 2.3 Ω, what is...
  11. endiewibowo

    How to calculate mutual inductance of a rectangular loop

    I am planning to build a rogowski coil but not the conventional one, which is a circular loop. Below is the example of a rogowski coil so you have the big picture of my question. In the picture, the current conducting wire (with current Ip) is encircled by a big circular loop rogowski coil...
  12. A

    Wire Attracts Loop - Electromagnetic Unit

    Homework Statement A rectangular loop of wire is placed next to a straight wire, as shown above. There is a current I in both the straight wire and the loop. The dimensions shown in the figure are a, b = 2.2a, and c = 8a. What is the magnitude of the force on the loop? Express your answer in...
  13. D

    MHB Deriving Formula for Magnetic Torque on Semicircular Loop

    I'm trying to derive a formula for the magnetic torque on a semicircular loop. what I've done so far is this The magnetic force on the non-curved loop is $\vec{F}_{x}=\int Idx\hat{i}\times B_{\circ}\hat{i}=0N$ for the curved loop $\vec{F}_{c}=\int_{0}^{\pi} Ird\phi\hat{\phi}\times...
  14. A

    MATLAB Roots of Polynomials by loop in matlab

    Dear Friends! I need to find roots of polynomials with variable coefficients, The command I used is w=0:50 A=w^2 B=w^3+2 C=w+2*w^2 D=w E=w./2 ss=[A B C D E] xi=roots(ss) by this I find all the roots of equation, I want to find velocities by setting v1=w/xi(1) v2=w/xi(2) v3=w/xi(3) v4=w/xi(4)...
  15. J

    Noise Issues with closed loop accelerometers

    Hi, Can anybody explain to me what the major noise issues are with mems closed loop accelerometers
  16. A

    How Does Magnetic Field Angle Affect Force on a Current-Carrying Loop?

    Homework Statement [/B] A circular loop of wire, of radius r, carries current I. It is placed in a magnetic field B whose straight lines seem to diverge from a point a distance d below the ring on its axis. (That is, the field makes an angle θ with the loop at all points, where tan(θ) = r/d.)...
  17. nuclearhead

    In what way is M-Theory different from Loop Quantum Gravity?

    I have been reading about M-Theory and LQG, and from what I read they are actually very similar. It seems that just a a string-world sheet is the same as a sum of an infinite number of Feynman diagrams, a membrane would be the sum of an infinite number of graphs or networks. Or as Susskind...
  18. R

    Area bounded by a curve's loop

    Homework Statement The area bounded by the loop of the curve ## 4y^2 = x^2(4-x^2) ## is in sq. units 7/3 8/3 11/3 16/3 Homework Equations NA The Attempt at a Solution By putting x = 0 and x = 2 I am getting y = 0. Getting complex y values after x exceeds 2. I am not getting where the loop...
  19. T

    Calculations of a half loop electromagnet

    Homework Statement This is a past exam question which I just for the life of me can't figure out. http://tinypic.com/r/2eq6ryo/8Homework Equations My guess is that the energy of the magnetisation is equal to the gravitational energy Relevant Equations: Ems = Mass * g * δ Where Mass = ρ *...
  20. cnh1995

    Induced current in a circular loop

    Hi friends..I'm struggling with an interesting puzzle...Suppose there is a circular conducting loop of radius 1/π cm, one half of which is made of a material with resistance 1Ω and the other half from a material with resistance 5Ω. If somehow, one managed to set up a changing magnetic field...
  21. Yorick Chupka

    Kirchoff's Loop Rule ∑ΔV=0 question

    Here is a portion of the explanation my book gives "Kirchoff's second rule follows the law of conservation of energy. Let's imagine moving a charge around a closed loop of a circuit. When the charge returns to the starting point, the charge-circuit system must have the same total energy as it...
  22. kelvin490

    Can Ampere's law be applied to 3D loop?

    Usually in textbooks Ampere's law is just illustrated using 2D loops which forms a plane. Can the law be applied to 3D loops which cannot form a plane surface within the loop? In a 3D loop which surface should we count when we count the current? In 2D case it is easy because there can only be a...
  23. K

    Is there a holographic principle in loop quantum gravity?

    for example, is loop quantum gravity/SF in 4 dimensions dual to a CFT in 3 dimensions? does a serious proposal of QG have to respect the holographic principle?
  24. S

    Magnetic field at the center of a square conducting loop

    Homework Statement Problem and solution attached Homework Equations B = [4uI/(4pi)]sin(theta1-theta2] The Attempt at a Solution I understand fully how to do it except determining the value of theta1 and theta2. The solution says theta1 is 45(deg) and theta2 is -45(deg). How did they get those...
  25. Essence

    Using ampere's law for a circular loop

    Homework Statement Sorry to bother you guys, I've heard that Ampere's Law is either ineffective for calculating the B field due to a circular loop or needs some modification (I wasn't sure which). I'm trying to figure out why this doesn't work so I can get a better understanding of Ampere's...
  26. I

    Magnetic Force from Current Loops: Relativistic Treatment

    There are plenty of examples where someone derives the magnetic force from a current carrying wire on a moving charged particle by looking at the frame of the particle and finding that the current has Lorentz contracted in such a way as to produce an electric field in an otherwise neutral wire...
  27. K

    Is Loop Quntuam gravity plausible formulation of quantum gravity

    what about loop quantum gravity? plausible formulation of quantum gravity in some universe. not necessarily ours.
  28. I

    Direction of induced EMF in loop

    Homework Statement Homework Equations Faraday's and Lenz' law. emf = -d(ф)/dt The Attempt at a Solution The current is increasing upwards during that time interval. Thus, by Right-Hand-Rule, the magnetic field goes into the page at the loop. Lenz' law says that the loop's induced emf...
  29. 2

    Back emf in a single loop of wire?

    I have been thinking about coils of wire carrying alternatingcurrent. From what I understand, a back emf is induced in the coil because there is a changing magnetic field around each individual loop of wire, and therefore there is a changing flux through each loop because the changing field...
  30. kelvin490

    How to prove Kirchhoff's loop rule?

    In common test books the "proof" is usually use an example of a simple one-loop system with battery and resistor. In such a case, the current actually goes round the loop and the same current flows throughout the loop. However in actual case, there may be different currents in different...
  31. Shinwasha

    Find the Magnitude of the Magnetic Field in a moving loop

    Homework Statement A conducting square loop placed in the xy plane (oriented with its horizontal and vertical sides parallel to the x and y axes) moves to the right across the y-axis at a constant speed of 2.0 m/s, a 0.63-V emf is induced in the loop. If the side length of the loop is 0.30 m...
  32. AionTelos

    What is the normal force on a block at the top of a loop?

    Homework Statement A block of mass m = 1.8 kg starts at rest on a rough inclined plane a height H = 8m above the ground. It slides down the plane, across a frictionless horizontal floor, and then around a frictionless loop the loop of radius R = 2.0 m. On the floor the speed of the block is...
  33. Shinwasha

    Calculate the magnitude of the induced EMF in the loop

    Homework Statement A square conducting loop lies in the xy plane of an xyz coordinate system. The loop is in a uniform magnetic field that points in the positive z direction and is decreasing at a rate of 0.070 T/s. What are (a) the magnitude of the induced EMF in the loop and (b) the direction...
  34. icecubebeast

    Java How do you handle multiple statements in Java's for loop?

    Hello, I haven't used the for loop in Java much, so I have a question. How do you put multiple statements inside the initialization, condition, and iteration portions of the for loop? I was coding and I came across this error: Exception in thread "main" java.lang.Error: Unresolved compilation...
  35. 10Exahertz

    Loop the Loop with Frictional Work

    Question: If the Radius of the loop-the-loop is 10meters, from how high above the ground should the object be dropped in order to successfully complete the loop, with friction? I attempted to solve it, but get the integral of cos(theta)dx, or more properly ds, and i do not know how to...
  36. A

    Python Python: How to show entered input results when entering a 0

    Homework Statement So, I have a program, which I am finishing but I apparently ran into a problem. In the program I have to make that whenever I enter a 0 in the input, the program will stop and print the results. Here's the program before I continue saying anything else: The Attempt at a...
  37. T

    What are the factors to consider when calculating heat change in a wire loop?

    I am trying to calculate what the heat change from room temperature is in a wire loop is. I have the power P, the thermal conductivity K , the radius of the wire "a" and the radius of the loop "r". Using Fourier's Law: P = -KA \frac{\Delta T}{\Delta x} I am unsure what to use as A and...
  38. D

    Fiber Optic Loop: How Long Before Photon Dissipation?

    Imagine a closed loop of fiber optics, How long will a photon be able to stay inside the loop before dissipating all it's energy, or does it not dissipate?
  39. J

    Loop falling into a constant magnetic field

    Homework Statement (Not this exactly, but it gets the idea across) I have a square loop of wire with sides L and at t=0, I have the bottom side of the loop right above a uniform magnetic field. So the flux is 0 at t=0, and right when I drop the loop, it is forced downwards at a magnitude...
  40. S

    Pressure Added to a Flow Loop by a Pump?

    Hi there, I have set up a flow loop for a uni experiment that will teach other students about the bernoulli equation. The loop will use a few working section that will increase and decrease pressure due to diameter, velocity and height changes. I first set-up my loop with the pump at the end...
  41. Shinwasha

    Circular loop with uniform magnetic field

    Homework Statement A current carrying wire is bent into a circular loop with radius R and lies in the XY plane. A uniform magnetic field in the +z direction exists through out the plane of the loop. What is the magnetic force exerted on the loop? Homework Equations Fb = I lb sin (theta) The...
  42. R

    Torque on cylinder due to current in loop

    Homework Statement The figure shows a cylinder of mass 3.38 kg, radius 5.20 cm and length 8.12 cm with 70 turns of wire wrapped around it lengthwise, so that the plane of the wire loop is parallel to the incline and contains the axis of the cylinder. What is the least current which while...
  43. N

    How Fast Will the Roller Coaster Car Be at the Top of the Loop?

    Homework Statement At one point in a roller-coaster, a single 300 kg car goes around a vertical, circular loop with a diameter of 24 m. It enters the loop at the bottom with a speed of 20 m/s. What will its speed be at the top? Homework Equations Kinetic Energy = 1/2mv^2 Gravitational Energy =...
  44. unknownv2

    Voltage of a Capacitor using Kirchhoff's Loop Rule

    (Sorry, meant to post this in Introductory Physics Homework, if someone could please move it.) 1. Homework Statement Use Kirchhoff's Loop Rule to solve for the voltages of the five capacitors in the network shown below. Homework Equations For Capacitance, C = q/v Kirchoff's juction law...
  45. Electro_vass

    Blackman's impedance formula (Open loop gain)

    Homework Statement Determine the input resistance using blackmans impedance formula. I know all the ressisor values, and transistor data. Homework Equations [/B] Blackmans impedance formula The Attempt at a Solution Our teacher has given us a example on how to find the open loop gain, but...
  46. Rapier

    Numerical Integration for Magnetic Field of a Loop of Wire

    Homework Statement Calculate the magnetic field of a current loop. Compare your numerical results with exact solution above the center of the loop. Investigate the effect of the grid size based on this comparison. Homework Equations dB = u0*I/4pi * (dL * R) / (R^2 + Z^2)^3/2 Bz = u0*I*R^2/ (2...
  47. A

    Asking a user for a correct input until they give a correct response

    Homework Statement I need a program (in PYTHON), which would ask a user his name and grade, then print them both. 1) If the name has a number it, the program has to ask the same question again until the name is entered correctly 2) The same with the grade. If it's higher than 10, the program...
  48. P

    Viability of closed loop deep geothermal plants?

    Hello everyone, Just posting this because I was wondering if it's possible to build 5-10km deep closed loop geothermal power plants from microgrid sizes of 1-5MWe to commercial power plant sizes of 0.5-1GWe that can have construction costs in the $3,000,000 per MWe range (similar to solar and...
  49. I

    What is the minimum height for an object to complete a loop without friction?

    1. Homework Statement A small mass m slides without friction along the looped apparatus shown in the attached file. (a) If the object is to remain on the track, even at the top of the circle(whose radius is r), from what minimum height hm must it be released(from rest)? (b) If it is released at...
  50. A

    Induced Voltage of a Magnetic Field passing through a loop

    Homework Statement A magnetic field passes through a circular loop of radius 14 cm and makes an angle of 65° with respect to the plane of the loop. The magnitude of the field is given by the equation: B = (1.25t2 - .500t + 4.00)T. a) Determine the voltage induced in the loop when t = 2.00 s...
Back
Top