Thread: how to terminate for loop

  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,897
    >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, 12:19 PM
  3. Terminate() inside constructor
    By Mario F. in forum C++ Programming
    Replies: 8
    Last Post: 07-14-2006, 03: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