decrementing for loop help needed

This is a discussion on decrementing for loop help needed within the C Programming forums, part of the General Programming Boards category; hiya Got a problem with a for loop for example Say I want it to start at 10, test for ...

  1. #1
    Registered User
    Join Date
    Jan 2006
    Posts
    3

    Lightbulb decrementing for loop help needed

    hiya

    Got a problem with a for loop
    for example
    Say I want it to start at 10, test for at less than 5 and decrement each time before printing, this has been driving me mad.

    this is what i thought it would be

    for(x=10; x<5; x--)

    printf("%d", x); etc

    when i do this for x is greater than 5 it works fine i.e x>5 and prints 109876 but for x<5 prints nothing any ideas.

    ad

  2. #2
    Registered User
    Join Date
    Mar 2005
    Posts
    140
    start at 10, test for at less than 5
    10 is not less than 5, so the loop condition fails immediately

  3. #3
    Registered User
    Join Date
    Jan 2006
    Posts
    3
    this is a question on a practise exam paper

    this is exactly what it says.....

    write a for statement which assigns x the value of 10, test if less than 5, and decrement each time the for loop is executed.????

    do you not think it can be done then???

    ad

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,852
    Yes it can be done.
    Yes, you've just written it successfully.
    Yes, you've just found out that it runs zero times.

    An odd question for sure, but your code matches the description.

  5. #5
    Registered User
    Join Date
    Jan 2006
    Posts
    3
    thanks it is really strange tho not sure if the q is a misprint

  6. #6
    Registered User
    Join Date
    Feb 2005
    Posts
    19
    What is the test for.

    Clarify that, and try nesting an "if" loop to achieve the desired result.

    Good luck.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. free needed or not?
    By quantt in forum Linux Programming
    Replies: 3
    Last Post: 06-25-2009, 10:32 AM
  2. C Programmers needed for Direct Hire positions
    By canefan in forum Projects and Job Recruitment
    Replies: 0
    Last Post: 09-24-2008, 12:55 PM
  3. C++ help needed
    By Enkindu in forum Projects and Job Recruitment
    Replies: 3
    Last Post: 09-01-2004, 12:24 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21