Note: This website is archived. For up-to-date information about D projects and development, please visit wiki.dlang.org.

Endless For Loop

Part of TutorialAdvanced

Description

This shows how to create an endless loop and break out of it if a given condition is met.

Example

void main()
{
    for()
    {
        if( /*condition met */ )
        {
            writef("You entered the correct answer.\n");
            break; // exits the endless loop
        }
        else
        {
            // do something like print an error message
            writef("Sorry, try again\n"); // after this, we go over from the start
        }
    }
    writef("Bye!");
}

Source

Submitted by anonymous contributor (Sat Jan 8, 2005 4:47 pm).

Link http://www.dsource.org/tutorials/index.php?show_example=141
Edited by jcc7
Date/Time Mon Mar 14, 2005 11:03 pm