View Single Post
Old Apr 25th, 2005, 9:27 PM   #2
bl00dninja
Programming Guru
 
bl00dninja's Avatar
 
Join Date: Oct 2004
Location: namespace std
Posts: 1,246
Rep Power: 5 bl00dninja is on a distinguished road
the easiest way to do a loop like you want is to start it with this expression here

while(1)
{
}
that automatically evaluates to true and will loop forever. then whenever you want to exit the loop you add the keyword
break;
after any time you want to exit the loop, usually when the user wants to quit the program.
you also use the keyword
continue;
after any time you want to start back up at the beginning of the loop

try something like this:
#include <stdio.h>

int main()
{
  while(1)
  {
    char uchoice;

    puts("wanna quit?");
    scanf("%c", &uchoice);

    if (uchoice == 'y')
    {
      break;
    }

  }

return 0;

}

or in C++
#include <iostream>
using namespace std;

int main()
{
  while(1)
  {

    char uchoice;

    cout<<"wanna quit?"<<endl;
    cin>>uchoice;
    
    if (uchoice == 'y')
    {
      break;
    }
  }
return 0;
}
__________________
i put on my robe and wizard hat...

Have you ever heard of Plato, Aristotle, Socrates?...Morons.
bl00dninja is offline   Reply With Quote