how to terminate for loop

This is a discussion on how to terminate for loop within the C++ Programming forums, part of the General Programming Boards category; this sounds like a simple job but i dont nkow how to terminate for loop. i tried things like Code: ...

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    30

    how to terminate for loop

    this sounds like a simple job but i dont nkow how to terminate for loop. i tried things like
    Code:
     for (i = 0; (i < 10) && !endForLoop; i++)
    endForLoop is bool type. but when i use this some part of my program doesn't worj properly.i want to add a condition within the body of for loop that will terminate or stop for loop regardless of the value of i.

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >i want to add a condition within the body of for loop that will terminate or stop for loop regardless of the value of i.
    The break keyword causes a loop to terminate prematurely:
    Code:
    for ( i = 0; i < 10; i++ ) {
      if ( something ) {
        break;
      }
    }
    My best code is written with the delete key.

  3. #3
    Registered User
    Join Date
    Mar 2004
    Posts
    30
    thnx

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. terminate() function
    By coletek in forum C++ Programming
    Replies: 2
    Last Post: 01-11-2009, 10:37 AM
  2. Terminate Boost::Thread
    By CornyKorn21 in forum C++ Programming
    Replies: 3
    Last Post: 06-03-2008, 01:19 PM
  3. Terminate() inside constructor
    By Mario F. in forum C++ Programming
    Replies: 8
    Last Post: 07-14-2006, 04:59 AM
  4. how to terminate a target thread
    By swaugh in forum C++ Programming
    Replies: 2
    Last Post: 01-24-2005, 11:13 AM

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