views:

97

answers:

5

Hi all

i just need to be able to loop a console app. what i mean by that is:

program start:
display text
get input
do calculation
display result
display text
get input.

REPEAT PROCESS INFINATE NUMBER OF TIMES UNTIL THE USER EXITS THE APPLICATION.
program end.

i hope that made sense. can anyone please explain how i would go about doing this? thank you :)

+4  A: 
while(true) {
  DisplayText();
  GetInput();
  DoCalculation();
  DisplayResult();
  DisplayText();
  GetInput();
}

The user can stop the program at any point with CTRL-C.

Is this what you meant?

Tiberiu Ana
+1  A: 

You can just put a loop around whatever you're doing in your program.

Joey
+1  A: 

Use a While loop

bool userWantsToExit = false;

get input

while(!userWantsToExit)
{

  do calc;
  display results;
  display text;
  get input;
  if (input == "exit") 
    userWantsToExit = true;
}

program end;
+1  A: 
Console.WriteLine("bla bla - enter xx to exit");
string line;
while(line = Console.ReadLine() != "xx")
{
  string result = DoSomethingWithThis(line);
  Console.WriteLine(result);
}
Traveling Tech Guy
+1  A: 

You could wrap the whole body of your Main method in program.cs in a while loop with a condition that will always be satisfied.

E.g (in pseudo-code)

While (true)
{
   Body
}

Kindness,

Dan

Daniel Elliott
thank you Dan that was very much appreciated. :)
baeltazor