Author 
Message 
swiftkillah

Posted: 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!






Sponsor Sponsor



Delos

Posted: Sun Jan 25, 2004 4:15 pm Post subject: (No subject) 


Sorry. I can't answer your questions for you.
I will emulate them so you can come up with the answers yourself.
A for loop is a counted loop.
Therefore:
for i : 1..10
end for
runs 1..10[inclusive] = 10 times.
If you have more than 1 for loop, then use this analogy:
A for loop is like a basket of eggs [/candy/pens/CDs]. Each basket has a specified number of eggs [/etc] in it. If I have 1 basket of 10 eggs, I have 10 eggs. But if I have 4 of these baskets, how many eggs do I have? Remember than the number of eggs in each basket will not change, just the number of baskets.
This works well for a single nested forloop. More? Just add more layers to the analogy.
Enjoy.
I'm going to let others pick apart your other q's. I'm a little surprised that your Gr10 compSci teacher would introduce you to so much...ah, well, I guess I just had a lessthanperfect gr10 compSci teacher.






McKenzie

Posted: Sun Jan 25, 2004 4:26 pm Post subject: (No 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 







Andy

Posted: Sun Jan 25, 2004 5:00 pm Post subject: (No subject) 


ohhh great... the new semester started...






DanShadow

Posted: Sun Jan 25, 2004 5:02 pm Post subject: (No subject) 


your asking the answers to questions on your test...lol.
I advise nobody to give directly the answers out...and good job for explaining guys.






swiftkillah

Posted: Sun Jan 25, 2004 5:20 pm Post subject: (No subject) 


no no these are the questions on a test i took last month. i just want the answers to help me study for the exam
btw thx for the help guys






