Thread: statement equivalents

  1. #1
    Registered User
    Join Date
    Jul 2002
    Posts
    48

    statement equivalents

    i picked letter C for #10 and letter B for #11.... am i correct?

    10. Which is the following statements is not equivalent to the other two (assuming that the loop bodies are the same)?
    (A) for (i = 0; i < 10; i++) ...
    (B) for (i = 0; i < 10; ++i) ...
    (C) for (i = 0; i++ < 10; ) ...

    11. Which is the following statements is not equivalent to the other two (assuming that the loop bodies are the same)?
    (A) while (i < 10) {...}
    (B) for (; i < 10;) {...}
    (C) do {...} while (i < 10);

  2. #2
    Registered User The Dog's Avatar
    Join Date
    May 2002
    Location
    Cape Town
    Posts
    788
    For #10 you were wrong unfortunately. The answer is B.
    For #10 you were wrong again unfortunately. The answer is C.

  3. #3
    Registered User The Dog's Avatar
    Join Date
    May 2002
    Location
    Cape Town
    Posts
    788
    FIXED

    For #10 you were wrong unfortunately. The answer is B.
    For #11 you were wrong again unfortunately. The answer is C.

  4. #4
    Registered User The Dog's Avatar
    Join Date
    May 2002
    Location
    Cape Town
    Posts
    788
    I would say C for #11 if all three are valid loops.

    >> (B) for (; i < 10 {...}

    that doesn't seem valid. the answer is probably B

  5. #5
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    Originally posted by The Dog
    I would say C for #11 if all three are valid loops.

    >> (B) for (; i < 10 {...}

    that doesn't seem valid. the answer is probably B
    the automatic smiley faces messed it up. its supposed to be

    Code:
    for (; i < 10; )
    { ... }

  6. #6
    Registered User The Dog's Avatar
    Join Date
    May 2002
    Location
    Cape Town
    Posts
    788
    then the answer would be C

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    The answer is C for both of them

  8. #8
    Registered User The Dog's Avatar
    Join Date
    May 2002
    Location
    Cape Town
    Posts
    788
    I disagree, I say B for the first one.

  9. #9
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Stop guessing and try writing some test code

  10. #10
    Registered User The Dog's Avatar
    Join Date
    May 2002
    Location
    Cape Town
    Posts
    788
    You're right, it is C.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Usefulness of the "else if" statement
    By gn17 in forum C Programming
    Replies: 7
    Last Post: 08-12-2007, 05:19 AM
  2. If Else statement problem
    By doofusboy in forum C Programming
    Replies: 2
    Last Post: 11-09-2005, 07:18 AM
  3. if/break statement
    By Apropos in forum C++ Programming
    Replies: 7
    Last Post: 02-22-2005, 02:33 PM
  4. string & if statement
    By Curacao in forum C++ Programming
    Replies: 4
    Last Post: 05-02-2003, 09:56 PM
  5. Uh-oh! I am having a major switch problem!
    By goodn in forum C Programming
    Replies: 4
    Last Post: 11-01-2001, 04:49 PM