- nickbenn (13:41:19):
- ok...let me see if anyone else comes in the next couple of minutes, and then we'll start. In the meantime, please connect to Mode via TelNet
- chtkjohn (13:41:32):
- We're not using it for our presentation but I am trying to learn while I can.
- nickbenn (13:41:52):
- sorry about that Kyla...I'm a bit out of it today
- chtkjohn (13:42:13):
- Ii am connectecd to mode do I need to open anything or change directories. Thats ok I am called a lot of things:)
- nickbenn (13:42:23):
- Well, then we will do a general Java session :)
- nickbenn (13:42:36):
- Nope, as long as you are in the directory you get when you first connect, that is fine.
- nickbenn (13:42:55):
- Ok, bit of history: Do you know who Karl Friedrich Gauss was?
- chtkjohn (13:43:30):
- I want to say mathematician. some type of ordering theorems?
- nickbenn (13:44:19):
- Good call. He was the preeminent mathematician between Newton and the 20th century (actually, he overshadows most of the 20th century mathematicians as well).
- nickbenn (13:44:45):
- We're going to reproduce a trick he was supposed to have done as a child - but we're going to do it in Java.
- chtkjohn (13:44:58):
- Was he the one with the bridges and how to go over them without crossing back or something?
- nickbenn (13:45:29):
- (Yes, the Bridges of Königsberg was a classic problem he solved)
- nickbenn (13:45:42):
- (Actually, he proved it could not be done.)
- nickbenn (13:46:34):
- Let me back a step first: in modeling a process which changes over time, one of the basic things we do is use, or write for ourselves, that stepping-forward logic.
- nickbenn (13:47:31):
- In general programming terms, when we want to step by a fixed increment, and we know where we're starting, and where we're stopping, we call this "iteration"
- chtkjohn (13:47:44):
- makes sense i think
- nickbenn (13:47:57):
- That's also what we're doing today, and that takes us back to Gauss.
- chtkjohn (13:48:19):
- ok i'm up for it
- nickbenn (13:48:32):
- In school one day, the teacher asked the class to add the numbers from 1 to 100, and give the sum.
- chtkjohn (13:48:54):
- i vaguely remember this
- nickbenn (13:49:05):
- All the students set to work scratching on their slates...but after a very short time, with very little work, Gauss gave the correct answer.
- nickbenn (13:49:20):
- After much more time, none of the other students had the correct answer.
- nickbenn (13:49:56):
- We're going to fix that: we're going to use the method the other students tried to use; but we're going to let Java keep track of the arithmetic, so we don't make errors.
- nickbenn (13:50:37):
- To do that, we're going to iterate, from 1 to 100, and keep a running total.
- nickbenn (13:50:39):
- Makes sense?
- chtkjohn (13:50:39):
- something with the N, N + 1, etc.? sorry i got booted off.
- chtkjohn (13:51:09):
- i missed in between the gauss gave the correct answer to iterate from 1 to 100
- nickbenn (13:51:15):
- Well his solution was much simpler, and quite intuitive. But we're going to solve it by brute force, with Java.
- chtkjohn (13:51:26):
- sounds good
- nickbenn (13:51:43):
- In Mode, we're going to create and edit a file called Gauss.java
- nickbenn (13:51:45):
- type:
- nickbenn (13:51:53):
- pico Gauss.java
- nickbenn (13:51:55):
- and hit enter
- chtkjohn (13:52:07):
- done
- nickbenn (13:52:11):
- that will put us in the editor, working on the file
- nickbenn (13:52:22):
- First, let's build the shell that is common to all Java programs:
- chtkjohn (13:52:35):
- ok
- nickbenn (13:52:37):
- type the following:
- nickbenn (13:52:39):
-
class Gauss {
public static void main (String [] args) {
// Place main program here
}
}
- nickbenn (13:53:36):
- remember: no mousing in the Mode window :)
- chtkjohn (13:54:05):
- ok i did, do i write out?
- nickbenn (13:54:15):
- Yes, but don't exit pico yet
- chtkjohn (13:54:33):
- ok
- nickbenn (13:55:12):
- Now, we need to iterate from 1 to 100, and keep a running total. So the first thing we'll do is write the code which counts from 1 to 100.
- chtkjohn (13:55:13):
- oops I put PL instead of Pl will that mess it up
- nickbenn (13:55:24):
- (Not at all. That's a comment.)
- chtkjohn (13:55:35):
- ok i'm ready
- nickbenn (13:55:46):
- In most programming languages, the way you iterate is called a "for loop"
- nickbenn (13:55:54):
- Java is no different.
- nickbenn (13:56:16):
- go to end of the line that has "//Place main program here"
- nickbenn (13:56:21):
- and hit enter, so you get a blank line.
- chtkjohn (13:56:54):
- ok
- nickbenn (13:57:16):
- starting in that blank line, type the following (hit enter as needed, to create more blank lines):
- nickbenn (13:57:38):
-
for (int counter = 1; counter <= 100; counter++) {
// We need to do something here
}
- nickbenn (13:58:47):
- when you're done, you should have something like this (don't worry if your indentation doesn't match mine):
- nickbenn (13:58:58):
class Gauss {
public static void main (String [] args) {
// Place main program here
for (int counter = 1; counter <= 100; counter++) {
// We need to do something here
}
}
}
- chtkjohn (13:59:14):
- got it
- nickbenn (13:59:32):
- Ok, now let's quickly look at what we have:
- nickbenn (13:59:51):
- in the line that has "for (int counter = 1; ..."
- chtkjohn (14:00:09):
- yes
- nickbenn (14:00:12):
- the "for" statement in Java has three parts, all within one set of parentheses:
- chtkjohn (14:00:39):
- wee're counteing by ones, less than 100 and adding what we count?
- nickbenn (14:00:44):
- the first is the initialization section. In this case, we are declaring a variable called "counter", and assigning the value 1 to it.
- nickbenn (14:01:16):
- in the second part, we're giving the condition under which we will keep iterating. In this case, we will keep iterating as long as the counter is less than or equal to 100.
- nickbenn (14:01:42):
- in the third part, we're saying what happens at the end of each iteration. In this case, we're incrementing the counter.
- nickbenn (14:02:07):
- (In java, "counter++" means "counter = counter + 1")
- nickbenn (14:02:39):
- So you're right, partly: we're counting up to one hundred, but what are we doing while we are counting?
- chtkjohn (14:03:23):
- I was kicked off after part 2, giving the condition
- nickbenn (14:03:41):
- ok...
- nickbenn (14:03:50):
- nickbenn: in the third part, we're saying what happens at the end of each iteration. In this case, we're incrementing the counter.
nickbenn: (In java, "counter++" means "counter = counter + 1")
nickbenn: So you're right, partly: we're counting up to one hundred, but what are we doing while we are counting?
- chtkjohn (14:04:22):
- adding the next increment?
- nickbenn (14:04:34):
- well, that's part of the counting.
- nickbenn (14:04:40):
- Oh, you mean taking the sum?
- nickbenn (14:04:49):
- Well, do you see us taking the sum in the code yet?
- chtkjohn (14:04:54):
- keeping a running total?
- nickbenn (14:05:12):
- Nope...in fact, we're not doing anything yet. All we're doing is counting... so far.
- chtkjohn (14:05:35):
- so how do we tell it to sum; give it another for statement?
- nickbenn (14:05:40):
- The comment line "// We need to do something here" is where we will do our work.
- chtkjohn (14:05:45):
- ok
- nickbenn (14:06:02):
- No, we're counting already, we don't need to count again. What we need to do now is keep a total of the numbers we count.
- chtkjohn (14:06:12):
- ok
- nickbenn (14:06:23):
- So, the first thing we do is create a variable where we will put the running total.
- nickbenn (14:06:32):
- Let's just call it "total"
- chtkjohn (14:06:51):
- so it will look like?
- nickbenn (14:06:54):
- So, at the end of the line that reads "// Place main program here", hit enter, to get a new line
- nickbenn (14:07:03):
- and type the following on the next line:
- nickbenn (14:07:12):
- (on the blank line, rather)
- nickbenn (14:07:34):
int total = 0;
- nickbenn (14:07:43):
- (the semicolon is critical!)
- nickbenn (14:08:01):
- what have we just done?
- chtkjohn (14:08:02):
- got it
- nickbenn (14:08:24):
- what does that line do?
- chtkjohn (14:08:37):
- the integer total is zerio so maybe its giving it a starting point?
- nickbenn (14:08:50):
- Yes, and more.
- nickbenn (14:09:15):
- We are declaring an integer-type variable called "total", and we're giving it an initial value of zero.
- nickbenn (14:09:27):
- your program should now read like this:
- nickbenn (14:09:29):
class Gauss {
public static void main (String [] args) {
// Place main program here
int total = 0;
for (int counter = 1; counter <= 100; counter++) {
// We need to do something here
}
}
}
- chtkjohn (14:10:00):
- oops i put it in the wreong place let me correct it
- nickbenn (14:10:07):
- ok
- chtkjohn (14:10:57):
- ok
- nickbenn (14:11:16):
- Ok...
- nickbenn (14:11:26):
- now, we have a variable to hold the running total...
- nickbenn (14:11:44):
- we have a "for loop" which will count from 1 to 100...
- nickbenn (14:11:47):
- what are we missing?
- chtkjohn (14:12:10):
- how does it know to stop looping?
- nickbenn (14:12:35):
- the second part of the statement in parentheses after "for" says "counter <= 100"
- chtkjohn (14:12:49):
- so it will stop automatically loopoing at that point?'
- nickbenn (14:12:58):
- that means, as soon as the counter is not less than or equal to 100, the loop stops
- chtkjohn (14:13:13):
- ok
- chtkjohn (14:13:34):
- so we need... i am not sure what!
- nickbenn (14:13:40):
- Ok, but we're still missing something. We're initializing our running total, and we're counting...
- nickbenn (14:13:48):
- but we're not yet adding to our running total.
- chtkjohn (14:14:02):
- no summation command?
- nickbenn (14:14:44):
- right. Now, in a "for loop" in Java, the stuff between those curly braces after the "for" statement is what gets executed every time we increment our counter.
- nickbenn (14:14:53):
- So that's where we'll add to the running total.
- nickbenn (14:15:08):
- go to the end of the line with "// We need to do something here", and hit enter
- chtkjohn (14:15:15):
- which is why we said do something here?
- nickbenn (14:15:20):
- Yep :)
- chtkjohn (14:15:33):
- ok
- nickbenn (14:15:42):
- in the blank line, type the following:
- nickbenn (14:15:52):
total += counter;
- chtkjohn (14:16:15):
- done
- nickbenn (14:16:21):
- (again, the semi-colon is critical)
- chtkjohn (14:16:44):
- got it
- nickbenn (14:16:58):
- Now, this is a little bit of Java shorthand. "total += counter;" is the same as "total = total + counter;"
- chtkjohn (14:17:15):
- makes sense to me
- nickbenn (14:17:22):
- As an aside, we see that there are actually three ways we can add 1 to a number in Java:
- nickbenn (14:17:29):
- number = number + 1;
- nickbenn (14:17:32):
- number += 1;
- nickbenn (14:17:35):
- number++;
- nickbenn (14:18:03):
- Now, your program should read as follows:
- nickbenn (14:18:14):
class Gauss {
public static void main (String [] args) {
// Place main program here
int total = 0;
for (int counter = 1; counter <= 100; counter++) {
// We need to do something here
total += counter;
}
}
}
- chtkjohn (14:18:30):
- got it
- nickbenn (14:19:17):
- As another aside: the variable names "counter" and "total" are not magic by any means. We simply created variables with those names, because those names made sense.
- nickbenn (14:19:47):
- we could have called them "x" and "y", "widget" and "wadget", etc.
- chtkjohn (14:20:07):
- if we were adding by twos would we put int counter=2 and could we use number++; to add by twos?
- nickbenn (14:20:41):
- instead of counter++, we would use something like "counter += 2" in the third part of that parentheses after "for"
- chtkjohn (14:20:55):
- ok
- nickbenn (14:21:21):
- Ok. We're initializing our total; we're counting from 1 to 100; we're adding the current counter value to our total.
- nickbenn (14:21:28):
- Is there anything else we need to do?
- chtkjohn (14:22:18):
- i got booted after you answered my questions about counting bny twos
- nickbenn (14:22:37):
- nickbenn: Ok. We're initializing our total; we're counting from 1 to 100; we're adding the current counter value to our total.
nickbenn: Is there anything else we need to do?
- chtkjohn (14:23:07):
- probably but i don't kknow what
- nickbenn (14:23:38):
- Well, Gauss's teacher said: Add the numbers from 1 to 100, and give the sum.
- nickbenn (14:23:50):
- Do we have any way of reporting the final sum?
- chtkjohn (14:23:58):
- so we need it to runa dn tell us the sum at the end
- chtkjohn (14:24:09):
- no we don't
- nickbenn (14:24:35):
- When we're done counting, but before the program finishes, it should display the sum.
- chtkjohn (14:24:52):
- should we try it?
- nickbenn (14:24:57):
- where in our code do you think we should make that happen?
- chtkjohn (14:25:29):
- in another set of curley brackets at the end of total=counter line
- nickbenn (14:26:36):
- CLose...everything in that set of curly braces (after the "for") gets executed every time we iterate. We don't want to display the sum every time; we only want to display it after the iteration is done.
- chtkjohn (14:27:12):
- so it should be before teh last set of curley brackest
- nickbenn (14:27:20):
- So, go to the line with the right curly brace, the next line after the line "total += counter;", and hit enter.
- nickbenn (14:27:54):
- our new, blank line should be before the last 2 right curly braces
- nickbenn (14:29:33):
- Sorry about that...
- chtkjohn (14:29:47):
- hey I understand
- nickbenn (14:30:17):
- the second-to-last curly brace is the end of the definition of the method "main", which is the "guts" of t he Java program. So, we need our new line to be inside that set of curly braces.
- nickbenn (14:30:31):
- So, in the new line, type the following:
- nickbenn (14:30:39):
- System.out.println ("Sum = " + total);
- nickbenn (14:31:11):
- Your program should now read as follows:
- nickbenn (14:31:50):
-
class Gauss {
public static void main (String [] args) {
// Place main program here
int total = 0;
for (int counter = 1; counter <= 100; counter++) {
// We need to do something here
total += counter;
}
System.out.println ("Sum = " + total);
}
}
- chtkjohn (14:31:58):
- Is there a space after println before ( ?
- nickbenn (14:32:10):
- There can be, but there doesn't have to be.
- chtkjohn (14:32:23):
- ok done
- nickbenn (14:32:42):
- Cool...
- nickbenn (14:33:00):
- look it over...make sure you don't have parentheses where you need curly braces, and vice versa.
- chtkjohn (14:34:02):
- Sorry I lost it after cool
- nickbenn (14:34:13):
- nickbenn: look it over...make sure you don't have parentheses where you need curly braces, and vice versa.
- nickbenn (14:34:31):
- And make sure the comment lines start with two forward slashes, without any space between them.
- nickbenn (14:35:10):
- All set?
- chtkjohn (14:35:16):
- i think i'm ok
- nickbenn (14:35:34):
- ok...write it out (Ctrl-O), and exit pico (Ctrl-X).
- chtkjohn (14:35:57):
- ok
- nickbenn (14:36:12):
- now, what do we need to do, if we actually want to run this thng and get the answer (which, of course, we do)?
- chtkjohn (14:36:22):
- compile it?
- nickbenn (14:36:28):
- yep...
- nickbenn (14:36:34):
- at the mode prompt, type:
- nickbenn (14:36:40):
- javac Gauss.java
- chtkjohn (14:37:02):
- dddone, no news is good news
- nickbenn (14:37:06):
- Rock on!
- nickbenn (14:37:11):
- Ok, now let's run it:
- nickbenn (14:37:14):
- java Gauss
- chtkjohn (14:37:32):
- 5050?
- nickbenn (14:37:37):
- Very good!
- nickbenn (14:37:41):
- That is exactly the answer
- chtkjohn (14:37:52):
- How di d he do it in his head?
- nickbenn (14:37:57):
- By the way, Gauss got the answe by recognizing...
- nickbenn (14:38:14):
- 1 + 100 = 101...2 + 99 = 101... 3 + 98 = 101...
- nickbenn (14:38:15):
- etc.
- nickbenn (14:38:27):
- all the way to 50 + 51 = 101
- chtkjohn (14:38:43):
- so he multipled 50 times 101?
- nickbenn (14:38:46):
- So, there are 50 pairs of numbers, and each pair adds up to 101. So, the sum must be 50 * 101
- nickbenn (14:38:51):
- Which is (of course) 5050
- chtkjohn (14:39:05):
- to be so brilliant!
- nickbenn (14:39:32):
- yes, and he was supposedly 4 years old or so at the time :)
- chtkjohn (14:39:38):
- I can't even recognize which pairs of socks I have
- nickbenn (14:39:44):
- Ok...last part of the exercise:
- chtkjohn (14:39:49):
- ready
- nickbenn (14:40:31):
- We're not satisfied with the problem Gauss's teacher gave. We want our program to take the sum from 1 to any positive integer.
- nickbenn (14:40:38):
- E.g. 1 to 500, 1 to 1000, etc.
- nickbenn (14:41:02):
- (Of course, even without Gauss, we know there is a more efficient way of doing this, but that's ok.)
- chtkjohn (14:41:15):
- crap, i has hoping you would say by twos, alright then do we change <100 to n?
- nickbenn (14:41:45):
- Well, you asked for it :) Let's let our program read two values from the command line:
- chtkjohn (14:41:53):
- ok
- nickbenn (14:41:53):
- the increment, and the stopping point
- nickbenn (14:42:14):
- so, we could count to 1000 by threes...or to 500 by sixes...etc.
- nickbenn (14:42:29):
- let's edit the program:
- nickbenn (14:42:32):
- pico Gauss.java
- chtkjohn (14:42:52):
- ready
- nickbenn (14:43:29):
- ok, after the comment line that reads "// Place main program here", hit enter to create a new line.
- nickbenn (14:43:37):
- In the new line, type:
- nickbenn (14:43:52):
int increment = Integer.parseInt (args [0]);
- nickbenn (14:44:45):
- what does that line do?
- chtkjohn (14:46:28):
- i got booted vbefore I could save teh parselnt line, hang on
- nickbenn (14:46:37):
- ok
- nickbenn (14:46:49):
- the line should read:
- nickbenn (14:46:57):
int increment = Integer.parseInt (args [0]);
- nickbenn (14:47:26):
- (note that that is a capital i, not an L)
- nickbenn (14:47:58):
- what does this line do?
- chtkjohn (14:48:57):
- I am not sure but telling the increment could be anything? sounds lilke a spell form Harry Potter
- nickbenn (14:49:04):
- hahaha
- nickbenn (14:49:14):
- In English, we might say it thusly:
- nickbenn (14:49:50):
- declare an integer-type variable called "increment", and assign to it the value obtained by parsing the first item on the command line as an integer.
- chtkjohn (14:50:14):
- i think i understand
- nickbenn (14:50:18):
- Remember, "args" is the array of what is typed, after the program name, after the command line.
- nickbenn (14:50:33):
- args [0] is the first item, args [1] is the second, etc.
- nickbenn (14:50:51):
- But all of the items are strings... so we need to convert them into integers (for this program).
- nickbenn (14:51:03):
- that's what Integer.parseInt does.
- nickbenn (14:51:19):
- Now, at the end of that line, hit the enter key, to create a blank line.
- nickbenn (14:51:27):
- in the blank line, type:
- nickbenn (14:51:40):
- int limit = Integer.parseInt (args [1]);
- chtkjohn (14:52:29):
- ok
- nickbenn (14:52:39):
- your program should now look like this:
- nickbenn (14:52:54):
-
class Gauss {
public static void main (String [] args) {
// Place main program here
int increment = Integer.parseInt (args [0]);
int limit = Integer.parseInt (args [1]);
int total = 0;
for (int counter = increment; counter <= limit; counter += increment) {
// We need to do something here
total += counter;
}
System.out.println ("Sum = " + total);
}
}
- nickbenn (14:53:54):
- oops...ignore the change to the "for" line. That's what we're doing next ;)
- chtkjohn (14:53:58):
- wait a minute I think I missed something when I got booted. I need to change int counter to increment, etc in the for line, hang on
- nickbenn (14:54:20):
- Yes...we need to change the "for" line as follows (you didn't miss anything; I jumped the gun):
- nickbenn (14:54:31):
for (int counter = increment; counter <= limit; counter += increment) {
- chtkjohn (14:55:23):
- got it I think
- nickbenn (14:55:45):
- what this line now says is: "Iterate from a starting value of increment, as long as the counter is less than or equal to limit, and after each iteration add increment to the counter"
- nickbenn (14:55:58):
- make sense?
- nickbenn (14:57:05):
- Ready to compile?
- chtkjohn (14:57:38):
- Sorry, booted again.got it and when we put in the parselnt commands we told it what the increments and the limits would be by telling the program to ask for it?
- nickbenn (14:57:54):
- The program won't have to ask for it at all..
- nickbenn (14:58:17):
- we will type it in on the same line as the program name, which makes it available to the program in the "args" array.
- nickbenn (14:58:42):
- Want to try a compile?
- chtkjohn (14:58:42):
- like Gauss.java 5 if we count by fives?
- chtkjohn (14:58:52):
- yup, i'm ready
- nickbenn (14:58:53):
- more like:
- nickbenn (14:58:57):
- java Gauss 5 100
- nickbenn (14:59:01):
- to count to 100 by 5s
- nickbenn (14:59:07):
- Ok
- nickbenn (14:59:21):
- Write the file out (Ctrl-O), and exit Pico (ctrl-X)
- chtkjohn (14:59:23):
- so compoile the new one first right?
- nickbenn (14:59:31):
- Then compile:
- nickbenn (14:59:36):
- javac Gauss.java
- chtkjohn (15:00:11):
- mad e two mistakes. let me find them
- nickbenn (15:00:33):
- Ok...feel free to type the error message, and I'll help, if you like.
- chtkjohn (15:01:32):
- It is saying I shouldn't have a period before parselnt after INteger
- nickbenn (15:01:51):
- Make sure it is written exactly as follows:
- nickbenn (15:02:01):
- int increment = Integer.parseInt (args [0]);
- nickbenn (15:02:32):
- No space before and after the period. "Integer" with a capital "i". "parseInt" with a lower-case "p", and a capital "i".
- chtkjohn (15:03:18):
- Got it I saw parse lnt not parse Int.
- nickbenn (15:03:43):
- Yes, it is short for "parse integer"
- chtkjohn (15:04:25):
- worked great this time. that makes more sense than my Harry Potter parsel
- nickbenn (15:04:31):
- Hahahahaha
- nickbenn (15:04:41):
- ok...did you get a clean compile?
- chtkjohn (15:04:45):
- perfect
- nickbenn (15:04:48):
- Great.
- nickbenn (15:04:59):
- Now, let's try a sum we know: from 1 to 100.
- chtkjohn (15:05:03):
- ok
- nickbenn (15:05:05):
- java Gauss 1 100
- chtkjohn (15:05:26):
- worked great
- nickbenn (15:05:35):
- now, try another one we know:
- nickbenn (15:05:41):
- java Gauss 3 9
- nickbenn (15:05:47):
- which will add 3 + 6 + 9
- nickbenn (15:05:55):
- (counting to nine, by threes)
- nickbenn (15:06:05):
- that should give us 18
- chtkjohn (15:06:11):
- worked good
- nickbenn (15:06:21):
- great. Now try something outrageous:
- nickbenn (15:06:27):
- java Gauss 17 10000
- nickbenn (15:07:03):
- (add the numbers from 17 to 10000, counting by 17s)
- chtkjohn (15:07:10):
- woah, 2943822 you won't make me check it will you?
- nickbenn (15:07:14):
- hahaha...
- nickbenn (15:07:18):
- no. it's correct.
- nickbenn (15:07:29):
- Very good!
- chtkjohn (15:07:41):
- cool
- nickbenn (15:08:16):
- So now we have seen how to create a loop which iterates over a range of numbers, incrementing by one, or by any other positive integer, and adding all of the number up.
- nickbenn (15:09:03):
- we use the same basic technique to increment one step at a time in a math model of a real world problem, such as (for example), iterating year by year through a population model.
- nickbenn (15:09:45):
- The main difference is what we do inside the loop: this time, we simply added to a running total; in a population model, we would compute the projected population for the current year, based on our model.
- chtkjohn (15:10:00):
- I lost it after 'adding all the numbers up' but I think this is very cool. I will try to impress myhusband with it.
- nickbenn (15:10:15):
- nickbenn: we use the same basic technique to increment one step at a time in a math model of a real world problem, such as (for example), iterating year by year through a population model.
nickbenn: The main difference is what we do inside the loop: this time, we simply added to a running total; in a population model, we would compute the projected population for the current year, based on our model.
- chtkjohn (15:10:35):
- ggot it
- nickbenn (15:10:48):
- there you go :)
- nickbenn (15:10:52):
- Any questions?
- chtkjohn (15:11:12):
- Thank you. I feel like I got my very own private lesson. Thanks.
- nickbenn (15:11:23):
- You're quite welcome.
- chtkjohn (15:12:04):
- I am going to use it to demonstrate to my girls how much they'll have in saving minus the interest after I keep donating to their accoutns every payday.
- nickbenn (15:12:41):
- One question for you: we saw that adding by threes, to 9, gives us a sum of 18. What do you think our program will do, if we count by threes to 10 (instead of 9)?
- chtkjohn (15:13:14):
- quit at 9? we didn't give it an 'or' command
- nickbenn (15:13:32):
- Well, it will start at 3...
- nickbenn (15:13:35):
- then go to 6...
- nickbenn (15:13:38):
- then go to 9...
- nickbenn (15:13:53):
- then, when it goes to 12, it will fail the condition of "counter <= limit"
- nickbenn (15:13:56):
- so it will stop.
- chtkjohn (15:14:04):
- ok
- nickbenn (15:14:06):
- And the sum will be the same as if we just went to 9
- chtkjohn (15:14:23):
- like you can't count half a person in teh census.
- nickbenn (15:14:28):
- exactly
- nickbenn (15:14:38):
- or half a kangaroo :)
- chtkjohn (15:14:49):
- ahh yes
- nickbenn (15:15:32):
- That's it :)
- chtkjohn (15:15:38):
- well thank you, I am going to go start dinner and get my reflections ready. Thank you so much. Bye for now.
- nickbenn (15:16:14):
- bye!