sorry i know its probly an easy question

This is a discussion on sorry i know its probly an easy question within the C++ Programming forums, part of the General Programming Boards category; hi im just wondering how to make a program that has lots of loops i wont put any code because ...

  1. #1
    Registered User
    Join Date
    Dec 2005
    Posts
    118

    sorry i know its probly an easy question

    hi im just wondering how to make a program that has lots of loops i wont put any code because it will probly be ugly so the format of my progam is
    Code:
    loop1 till loop1 is finished
    loop2 till loop2 is finished 
    back to loop1 to check if still true
    i havent got a compiler yet so i cant check how to end loop 1
    ive read the tutorials but im missing something please help.
    all i need is what code stops loop1 to let loop2 start

  2. #2
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    back to loop1 to check if still true
    If loop1 finishes, then it's conditional evaluated to false, so going back to check if the conditional is true is pointless.

    all i need is what code stops loop1 to let loop2 start
    Code:
    #include <iostream>
    using namespace std;
    
    int main()
    {
    	int num = 1;
    	
            //loop1
    	while(num <= 10)
    	{
    		cout<<num<<" ";
    		++num;
    	}
    	cout<<endl;
    	
            //loop2:
    	while(num < 20)
    	{
    		cout<<num<<" ";
    		++num;
    	}
    	cout<<endl;
    
    	return 0;
    }

  3. #3
    Registered User
    Join Date
    Dec 2005
    Posts
    118
    thank you that will help me soo much i appreciate this.
    hopfully it will help me to become a fabled programmer one day

  4. #4
    Registered User
    Join Date
    Dec 2005
    Posts
    118
    oh sorry one more thing how would i get loop 1 to be check if its still false after loop2 has ended?

  5. #5
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,062
    If loop two has effects on the condition of loop one, then you'd probably want loop two nested in loop one.
    Sent from my iPadŽ

  6. #6
    Registered User
    Join Date
    Dec 2005
    Posts
    118
    well im not sure how to do that =p so if you know how i can get this to happen:
    Code:
    do loop1 till condition met
    do loop2 till condition met
    do loop1 if condition still met end else do loop1 condition met
    do loop2 till condition met
    and so on and so on. i havent wrote the program yet but it will end and is not infinate

  7. #7
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,062
    Like this:

    Code:
    while( loop1 == false ) {
         // Code here
         if (loop1 == true) {
            while( loop2 == false ) {
               // Code here
            }  // End of loop2
         } // end if
    } // End of loop1
    In otherwords... start loop one if it's condition isn't met. If by the time you get to the second loop, the condition is true, do loop 2 if it's condition isn't met. When loop2's condition is met, end the loop, if loop1's condition is false again by this point, loop again.
    Last edited by SlyMaelstrom; 12-02-2005 at 11:29 AM.
    Sent from my iPadŽ

  8. #8
    Registered User
    Join Date
    Dec 2005
    Posts
    118
    cool thank you ill get straight on it ill let u know how i get on

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Another Embarassingly Easy Question
    By almo89 in forum C Programming
    Replies: 2
    Last Post: 02-11-2006, 03:59 PM
  2. This is hopefully an extremely easy question...
    By rachaelvictoria in forum C Programming
    Replies: 2
    Last Post: 11-07-2005, 12:36 AM
  3. 4 easy question
    By Zeratulsdomain in forum C++ Programming
    Replies: 2
    Last Post: 10-15-2005, 10:43 PM
  4. Quick Easy Question
    By St0rmTroop3er in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 02-24-2004, 12:08 AM
  5. Easy Question
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 08-12-2002, 12:19 PM

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