# Learning to code. • Page 3

• Page

of 8

• monkehhh 17 Mar 2012 15:39:39 4,769 posts
Seen 7 hours ago
Registered 9 years ago
 Post deleted
• monkehhh 17 Mar 2012 15:40:08 4,769 posts
Seen 7 hours ago
Registered 9 years ago
 Forum's eating mah posts!
• Deleted user 17 March 2012 15:45:22
 That one is a bitch, I was struggling with it yesterday The point of the for loop is to keep iterating until the condition is met, remember: initialization; condition; increment.
• Deleted user 17 March 2012 16:07:08
 IPhattso wrote: @RedSparrows Step 1: remind yourself what raising a number to a power does. Think through how you would write it mathematically rather than code. Given the inputs (2,2) do it by hand to work out what you expect the result to be. This will help you understand what this code is trying to achieve. Step 2: remind yourself that the 'for' loop executes the code between the braces {} according to its limits (in this case, from 0 to exponent-1). Step 3: write out the value of 'results' for each step in the loop. i.e. what is the value of 'result' after the first pass through the loop, then what is it after the second? Hopefully this will look a little like what you learned in Step 1. Important concepts these - important that you grasp them rather than get given the answer in an explanation*. Good luck! * no doubt someone will take pity if you continue to have trouble. Thanks man. You are quite right. Need to understand. My brain is attuned to rhetoric and discourse, not maths! Time to dig in. Having a lot of fun Edit: I can kind of see what it is doing. If we wanted 3topowerof5, it has to 'add' a three to multiply until it reaches 5, I.e = to exponent. But still confused! More work. Edited by RedSparrows at 16:32:09 17-03-2012
• Deleted user 17 March 2012 17:00:57
 Right. Let's use 3to5. If first result is 1, as defined, then 1 x 3 = 3. 3 is new result. 3x3 = 9. And so on, until we have the FIFTH result, I.e the same number as the exponent. Correct? So the loop adds another sum until has done a number of sums = to the exponent. Correct?
• [maven] 17 Mar 2012 17:04:46 5,553 posts
Seen 1 day ago
Registered 14 years ago
 There are no sums (other than the loop-counter).
• monkehhh 17 Mar 2012 17:06:59 4,769 posts
Seen 7 hours ago
Registered 9 years ago
 Yep, when 'i' isn't less than the exponent anymore it stops looping and returns the result. Another way to do this would be to initially set result to the base and loop one less time - if that makes sense
• Deleted user 17 March 2012 17:08:49
 Yeah I see. Maven I was describing it how I saw it in my head. Not up on the lingo it's doing it all at once I know.
• Deleted user 17 March 2012 17:55:58
 Recursion makes me gooey in head.
• mal 18 Mar 2012 02:41:44 28,861 posts
Seen 45 minutes ago
Registered 16 years ago
 Edit: This is not the forum to post code on. Edited by mal at 02:43:09 18-03-2012
• Phattso 18 Mar 2012 15:30:56 22,312 posts
Seen 4 hours ago
Registered 14 years ago
 RedSparrows wrote: Recursion makes me gooey in head. Be careful - in programming recursion has a very different meaning (methods that call themselves in-line). What you have here is simply a function that returns a result, and the function happens to contain a loop. Unless I've read the code snippet wrongly.
• mal 18 Mar 2012 15:50:50 28,861 posts
Seen 45 minutes ago
Registered 16 years ago
 Yeah, I reimplemented that power code using recursion, but unfortunately the forum ate my code. Hmm, wonder if I can do it in pseudocode? Edit: Nope, forum eats that too. Edited by mal at 15:51:51 18-03-2012
• Phattso 18 Mar 2012 16:00:04 22,312 posts
Seen 4 hours ago
Registered 14 years ago
 It's interesting watching you guys get to grips with this stuff. I had to delve deeeeep into the past to remember a time when I didn't implicitly understanding all this. I think I can trace my "Eureka!" moment with this back to 1992 or so. I'd been doing assembler for a few years, but getting to grips with a higher level language was a real effort. It's very rewarding when it all clicks into place in your brain - I'm slightly envious that you're all getting that. Been a while for me now.
• Deleted user 18 March 2012 17:54:29
 I'm on some recursion now, is why I said it. Finally clicked that the computer wad viewing what I was in a totally different way. It's cooked my noggin', but I really enjoy it!
• Deleted user 20 March 2012 15:55:43
 Omnonomnom ternary operators omnomnom I like you best omnomnom In other news, I have been watching some MIT CS lectures - REALLY useful for getting into the right way of thinking.
• monkehhh 20 Mar 2012 19:56:45 4,769 posts
Seen 7 hours ago
Registered 9 years ago
 It is fun learning new stuff - I'm currently delving in to the deep, dark corners of our GIS systems at work in preparation for starting my masters. For a game that gives that similar feeling of "what is this?!" / "fuck me, I'm clever" - play SpaceChem
• Deleted user 20 March 2012 20:33:20
 @Red, got a link for those lectures?
• mal 21 Mar 2012 00:34:12 28,861 posts
Seen 45 minutes ago
Registered 16 years ago
 RedSparrows wrote: Omnonomnom ternary operators omnomnom I like you best omnomnom What a strange strange man. Go learn some Forth if you like those.
• Deleted user 21 March 2012 17:13:02
 Mr-Brett wrote: @Red, got a link for those lectures? Is the one I am using! @mal - I like them as they make my brain happier than lots of if/else stuff! Not sure why. Edited by RedSparrows at 17:13:33 21-03-2012
• Deleted user 21 March 2012 17:36:47
 Cheers Red. I've not got to ternary operators yet, hopefully they don't hurt my brain as much as loops do.
• Deleted user 21 March 2012 18:59:51
 I like them because they simplify, at least visually, conditional statements. Loops are the biggy for me too. The MIT lectures are great simply at explaining how to think - that's the whole point of them. They're taught by and too people with far more technical ability than me, but I still understand them. Lecture 1 is largely admin for the course, as you'd expect, but it gets going.
• Deleted user 22 March 2012 20:37:23
 Done the first ternary operators section, I have to agree, much nicer than 'if else'. Just starting the second lecture video
• BravoGolf Moderator 22 Mar 2012 21:34:11 12,771 posts
Seen 4 days ago
Registered 15 years ago
 Hello World! .... /leaves
• mal 22 Mar 2012 23:51:50 28,861 posts
Seen 45 minutes ago
Registered 16 years ago
 God, I hate ternary operators. Too terse, too hard to remember unless you use them a lot (I should probably learn a mnemonic for condition?if_true:if_false). But on the other hand I love list comprehension and lambda functions, so maybe I've no leg to stand on.
• Deleted user 23 March 2012 12:59:48
 Oh god I hate the FizzBuzz++ project, it's like it was written by a robot.
• Deleted user 23 March 2012 17:28:30
 Yeah the fizzbuz++ one is not written that well. It's kind of annoying the whole thing isn't by one person. I feel like I have covered the same thing twice at times, but written in different ways. Still, good practise.
• Deleted user 23 March 2012 17:49:14
 Yeah I'm happy for the practice, so I don't mind much about that kinda thing and sometimes they aren't brilliantly written but you get the jist. With FizzBuzz++ though you're working with some concepts which can be pretty hard to get your head around so it'd be nice if a bit more care was taken with writing it. Oh well, onwards and upwards!
• Deleted user 23 March 2012 18:19:43
 Yeah, that one just decides to introduce Objects and another key word, not to mention a really odd set of values.
• Deleted user 27 March 2012 11:51:59
 I wonder if someone here might be able to help me with one of the codecademy exercises, it's Primitives in JavaScript » Section 4 Boolean in the wild #2. I can't figure out why my code doesn't work, I've put it here.
• Phattso 27 Mar 2012 11:54:12 22,312 posts
Seen 4 hours ago
Registered 14 years ago
 i & 3
• Page

of 8