Thread: return to start coding?

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

    return to start coding?

    what coding would restart a program at its completion? i have no idea :P

    thanks.

  2. #2
    The Richness... Richie T's Avatar
    Join Date
    Jan 2006
    Location
    Ireland
    Posts
    469
    a loop - there are two main types - a while and a for loop, each with their own syntax. there's also the do...while loop - less common, and its used to ensure that a loop runs at least once.

    a while loop is typically used when you don't know how many times you want to loop over - ie a user will normally choose when to break the loop. a for loop is a different beast, whereby some variable changes every loop and once this variable reaches a certain value, the loop terminates. here's a while loop:

    Code:
    while (condition)
    {
             /*code*/
    }
    an example of this would be:

    Code:
    while (variable != 0)
    {
            /*code*/
    }
    as you can see, the statement uses a boolean test - if somewhere in the code within the loop, variable becomes set to zero, the loop will exit. notice the following:

    Code:
    while (1)
    makes a loop run infinitely (unless somewhere in the loop there is a line of code that says: break break is a command used to exit any loop type (once it is encountered)

    the for loop is used as follows:

    Code:
    for (variable1 = 0; variable1 < variable2; variable1++)
    {
            /*code*/
    }
    what this reads as is that once the loop is encountered in the code, variable1 is set to 0. then the loop checks the condition (the middle statement). if the condition is true, the third loop will run, at the end of which, condition 3, the increment is run. then the loop checks the conditions over. once the condition is false, the loop will break
    No No's:
    fflush (stdin); gets (); void main ();


    Goodies:
    Example of fgets (); The FAQ, C/C++ Reference


    My Gear:
    OS - Windows XP
    IDE - MS Visual C++ 2008 Express Edition


    ASCII stupid question, get a stupid ANSI

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Adventures in labyrinth generation.
    By guesst in forum Game Programming
    Replies: 8
    Last Post: 10-12-2008, 01:30 PM
  2. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  3. can some one please tell me the cause of the error ?
    By broli86 in forum C Programming
    Replies: 8
    Last Post: 06-26-2008, 08:36 PM
  4. C++ FTP class won't work
    By lord mazdak in forum C++ Programming
    Replies: 8
    Last Post: 12-18-2005, 07:57 AM
  5. opengl code not working
    By Unregistered in forum Windows Programming
    Replies: 4
    Last Post: 02-14-2002, 10:01 PM