Thread: Help 'do while' loop

  1. #1
    Registered User
    Join Date
    May 2003
    Posts
    2

    Help 'do while' loop

    Does not like my while statement. Help
    How to fix?

    do
    {

    /* several statements all work correctly */

    printf("Enter 'X' to exit program\n);
    scanf( " %c", &option);
    while (option != 'X' || option != 'x')
    }


    tia
    Otto

    Sorry about the lack of tags.

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    That isn't the syntax for a do...while loop. First you have do, then a statement or compound statement, while, and a semicolon:
    Code:
    do
        statement
    while (condition);
    Your code (assuming you've omitted nothing important) should be:
    Code:
    do
    {
        printf("Enter 'X' to exit program\n);
        scanf( " %c", &option);
    }
    while (option != 'X' || option != 'x');
    My best code is written with the delete key.

  3. #3
    Registered User
    Join Date
    May 2003
    Posts
    2
    Guys,

    Shame on me. I guess I was tired etc.
    Happens when trying a new language.
    Thanks again.

    Otto

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. nested loop, simple but i'm missing it
    By big_brother in forum C Programming
    Replies: 19
    Last Post: 10-23-2006, 10:21 PM
  2. While loop misbehaving (or misunderstanding)
    By mattAU in forum C Programming
    Replies: 2
    Last Post: 08-28-2006, 02:14 AM
  3. loop in a linked linked lists
    By kris.c in forum C Programming
    Replies: 6
    Last Post: 08-26-2006, 12:38 PM
  4. while loop help
    By bliznags in forum C Programming
    Replies: 5
    Last Post: 03-20-2005, 12:30 AM
  5. loop issues
    By kristy in forum C Programming
    Replies: 3
    Last Post: 03-05-2005, 09:14 AM