Not sure what type of looping I need to do for an assignment at school. So I need to calculate pi depending on the amount of iterations the user chooses to input. There is a formula I need to do with variables( the value of the variables changes every time it is looped, that’s why it needs to be looped) and I need to loop it however many times the user inputs. What kind of looping would I need to do, and can I also get an explanation on how to do it in codea?
Thanks
Also, how do you do an exponent in codea?
Like 5 to the power of some variable?
@JessicGriffin, which formula? And take a look at the ‘help’ topic… dave explained it… gave a whole piece of code, tho we don’t know if it is the right formula…
http://twolivesleft.com/Codea/Talk/discussion/4037/help#Item_39
@JessicGriffin See the discussion “Help”, near the bottom. I posted a program there for iterations of Pi. Maybe that will give you an idea, or just use it.
@JessicGriffin - if you want some simple code you can understand, you might try this. You only have to change the two lines marked EDIT.
function setup()
parameter.integer("Loops",1,1000,10) --change the number of loops here
parameter.action("Calculate",Iterate) --press button to run
end
function Iterate()
output.clear()
print("Calculating ",Loops," loops")
x=1 --starting value of your result EDIT
for i=1,Loops do
x=x+i^2 --your special formula goes here, note ^ is exponent EDIT
print(i,"=",x) --prints values for each loop
end
end