Author: swiftkillah [ Sun Jan 25, 2004 4:08 pm ] Post subject: Stupid Question Im taking basic Turing lessons in my Grade 10 computer science class. The problem is I suck ass at it and don't understand some of the basics. Im reveiwing for my exam and have looked through a couple past tests. I will post the questions that I coudn't get and would really appreciate if someone could explian them to me. thanks. 1. How many times will "Hello World" be outputed in the following example? for I: 1..10 for J : 1..5 put "Hello World" end for end for 2. What will the following program output? for I :3 .. 12 by 2 if I mod 3=1 then put I.. end if end for 3. How would u make the previous program output only even numbers? 4. how would u make the previous program make the numbers go backwards? i really ned to leanr how to do these kinds of questions. Thx in advance!

Author:  McKenzie [ Sun Jan 25, 2004 4:26 pm ]
Post subject:

#1 is called a nested for loop
what you need to be able to see is that the inner for will loop fully for EACH time the outer for loops. Now in this case it's a total of 50. This usually helps clear things up:
 code: for I: 1..10      for J : 1..5           put I:3,J:5      end for end for

#2 There are two things here. Do you know what mod does? and do you know how to trace a program?
mod
~~~
mod is the remainer you get with integer division. So
5 mod 2 = 1
20 mod 3 = 2
When you trace a proram make a table and try to follow the program one line at a time. If I traced that program it would look like:
 code: I | I mod 3 ||  Output ---------------------------  3 |    0    ||  5 |    2    ||     7 |    1    ||    7  9 |    0    ||    11 |    2    ||

 Author: Andy [ Sun Jan 25, 2004 5:00 pm ] Post subject: ohhh great... the new semester started...