New to Programming and Codea

Ha! Ha! Ha! :)) Good one.

Time to type the coooode! Ha! Ha! Ha! It’s all about the code and how you
code it! It’s about syntax and if you take it. It’s all about Lua and if you can learn it. It’s all about the pain and who’s gonna make it! I am the code you don’t wanna code me!

Pro Wrestling Entrance theme parody I just thought of.
Pretty Corny but anyway trying to have some fun.

Fun is why we’re all here!

Needs some help here. Right now I’m doing exercises from the ebook
Lua for beginners. I am trying to do the first loop exercise. I believe I have everything right
here. But the code keeps printing out 5050 instead of 100. I want find out what is going on and move on to the next exercise and not spend two hours trying to figure out why it’s not printing 100.
Please help!

The code is this

function setup()
  
  total=0
 
   for i = 1,100 do
    
    total = total + i 
end

print(total)
    
end

That’s because each time it runs the for loop, it adds more to it. If you want it to add one every time it runs the for loop, say total = total + 1. Every time it runs the for loop, i is one more. i, in that case, is basically how many times it’s ran the for loop. So it adds like this:

It's like this: total + index
0 + 1
1 + 2
3 + 3
6 + 4
10 + 5
15 + 6
21 + 7
28 + 8
36 + 9
45 + 10
55 + 11... etc. Ends up as 5050.

In short, what Dave said after this. :stuck_out_tongue:

What you’re doing is adding all of the numbers from 1 to 100. That adds up to 5050.

It’s not strange, if you want 100 do either total = i or total = total + 1

@strotherdw - I checked the ebook, and it says next to that example “Suppose I want to add up all the numbers from 1 to 100”, which is what the example does.

Keep trying, it is hard at first, but it gets easier, and then it is a lot of fun.

@Ignatz I’m still waiting for the fun part :frowning:

Strange, but thanks for letting me know. However I wish I was told this in the tutorial.

Perhaps in time I’ll get used to these kind of things.

be patient, it is hard at first. Codea is the most fun graphic programming language, but it is still hard work at first. If you ever learned a language, or music, or a new sport, you’ll know what I mean.

I probably should just go through one a chapter a day and then take a break the rest of the day and wait until the next day to start practicing again instead of spending an hour or two reading and doing 3 or 4 chapters in the tutorials. What do you think. Is that a better way for me to practice that way?

@strothererdw learning from a book is usually not much fun.
Alternatively, you could start from one of the ‘step by step projects’ publish recently, like a lunar lander. That would be much more fun.

the step by step tutorials are here (more will be added soon)

https://bitbucket.org/TwoLivesLeft/core/wiki/Step%20by%20step%20projects

@ignatz and to @Jmv38 An idea just occurred to me. I was thinking I could rotate. I could read and do a chapter of Ignaz’s Lua ebook for Beginners and then the next day do one or two of the step by step tutorials and practice more and play around by altering the code of the tutorials for myself to see what works and does not work. (I have encountered quite a few cool surprises when I altered a little bit of some sample codes.). Then the following day read and do a Lua chapter, and the next day do step by step tutorials and then the next day and so on.
What do you think of that plan?

Regarding adding numbers from 1 to 100, see http://www.americanscientist.org/issues/pub/2006/3/gausss-day-of-reckoning

@Andrew_Stacy Thank you for the link. :)>-

Regarding wrestling (aka Lua vs other programming languages) this my FALSE program for adding numbers from 1 to 100 (dedicated to @Andrew_Stacey): 100a:a;$1+*2/. :smiley:
(You can check it here http://www.quirkster.com/iano/js/false-js.html).

Edit: by the way, I dream of a FALSE interpreter in Codea (there is a javascript version, but I write javascript as I write klingon: nil). I-)

I love problems with solutions requiring insight. Try this one (@Andrew_Stacey has to do it in his head).

You are downloading several movies, and your browser estimates the time left for each one. But this is not accurate, because when each one finishes, the others speed up (assuming total bandwidth is constant). So, if the first of four, finishes, the others will speed up by 4/3.

Now, looking at all these estimates on the screen, how can you quickly figure out the time until all have downloaded? There is a surprisingly simple formula for the solution. But the big prize is for being able to explain as simply as possible why that formula is correct.

@Ignatz, and how the formula looks like?