Thread: question about for loop

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    84

    question about for loop

    i was wondering if this was ok in a for loop, I'm getting an error in my program and dont know if its coming from this. Basically I just want this to increment x while it calls up on another function f(y,z)

    Code:
                for ( a = 1.001, ( f(a,angle_theta) * f(b,angle_theta) )> 0 ||
                     a < 50, a = a + 2 )
                     
                     ;

    am I putting to much stuff in the for loop? I want it to break out of the for loop once the middle conditions aren't met, and i don't want the body of the loop to do anything, just keep incrementing a.


    Thank you

  2. #2
    Registered User white's Avatar
    Join Date
    Nov 2004
    Posts
    39
    you could try while instead of for

    Code:
    a = 1.001
    while (f(a,angle_theta) * f(b,angle_theta))> 0 || a < 50)
    {
    a = a+2;
    }
    ----------------

  3. #3
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    The parts of a for loop are split with a ; and not a ,
    Code:
                for ( a = 1.001; ( f(a,angle_theta) * f(b,angle_theta) )> 0 ||
                     a < 50; a = a + 2 )

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > I'm getting an error in my program
    Well posting the error message would be a good idea - no?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 02:51 PM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 05:51 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 01:47 AM