17 May, 2009

Chapter 6 Test - again!

In the Multiple Choice part, question 12 and 13, just wondering if anyone can help. As I understand it from the book, when you have a For ... Next loop that runs from 1 To 4 the loop will run 4 times and stop when it gets to 5. Therefore, in question 12 when the values are 1 To 25 with a Step of 3, that would be 1, 4, 7, 10, 13, 16, 19, 22 and 25 - hence looping 9 times ... but when we ran that code in VB it seemed to stop at 25 therefore only running 8 times. Does that make sense? So basically, do people think the answer to number 12 is 8 or 9, and along the same lines in the answer to number 13 3 or 4?? Can anyone help???

3 comments:

  1. Hi again Deb.

    My understanding is that "1" isn't a loop as it is the starting point. Therefore, the loop goes 4, 7, 10, 13, 16, 19, 22, 25. This makes it 8 times through as you can see.

    Question 13 would run the same way. There is no real definitive answer to this in the book. Nothing that says, "it will run this way, and that's because we don't count this as a loop" etc.

    I suppose you could look at it this way though, For intCount = 10 To 16 Step 2
    'Body of loop
    Next
    10 = true - run loop (1)
    12 = true - run loop (2)
    14 = true - run loop (3)
    16 = true - run loop (4)
    18 = false - no loop (0)

    Going by that, the loop would run 4 times.

    I know this probably hasn't helped at all, but I'm truly as confused as you are.

    Then again, you could ask Rachael tomorrow.

    Have a good one, see you Tuesday.

    Tim.

    ReplyDelete
  2. Hey Tim.

    Thanks for the response. Just checked with Rachael and for question 12, the loop does run on 1 as well as 4, 7, 10 ... so the answer would be that it executes 9 times. We all agree that it's 4 for question 13.

    See you tomorrow.

    Deb.

    ReplyDelete
  3. HI Deb.

    Yeah, I realised as I ran through the example that I was probably wrong about question 12. Like I said though, confusion was reigning supreme.

    Have a good one,

    Tim.

    ReplyDelete