Repeating Sequence
You how you put Console.WriteLine("Press Enter to continue");
and then you put Console.ReadLine();
Now i want it to say would you like another entry Y or N if they enter Y how do i repeat the process of going back to the excution of the program....basically how do i start it over...
I know it seems i am asking very basic question...but i started programming very differently than most developers...
[502 byte] By [
Dpowers] at [2007-12-16]
Hi,
Ok, lets dissect the statement:
do {
// Your logic should be here...
Console.Write("Quit (Y/N)? ");
} while (Console.ReadLine().ToUpper() != "Y");
the statements between do and while clauses would repeat until the expression in the while statement is true.
1. It will enter the loop, execute your logic and display "Quit (Y/N)? "
2. It evaluates the while statement.
3. Since the while statement includes a call to Console.Readline() the system then waits for an input from the user.
4. After a key has been entered it is then converted to Upper Case (String.ToUpper() function)..
5. It would then compare if the letter entered is equal to 'Y'.
- if yes, then the while statement is me, and the loop terminates.
- if No, the loops executes in the beginning...
cheers,
Paul June A. Domag
I understand the concept of the statement...But what makes the program repeat? You said the logic goes after the do...but what logic..is there some keyword that i am missing here is the entire sample code:
using
System;
class
Strings {
static void Main() {
string a,b,c; a = "Demetrius";
b = "Salena";
c = "Family";
Console.WriteLine("Enter Your Name");
Console.Read();
if ( a == "Demetrius") Console.WriteLine("This is Demetrius his girl is {0}", b);
else if( a != "Demetrius") Console.WriteLine("Enter another Choice");
if ( b == "Salena") Console.WriteLine("Salena boyfriend is {0}", a);
if ( c == "Family") Console.WriteLine("{0}, and {1} will start a {2}", a, b, c);
Console.WriteLine("Press Enter to continue");
Console.ReadLine();
do {
Console.Write("Quit (Y/N)? ");
}
while (Console.ReadLine().ToUpper() != "Y"); }
}
You know what i think i got it...for the do logic i belive i put the
Console.WriteLine("Enter Your Name");
Console.Read();
in the do logic so that when i enter N it goes back to these statements...what do you think
Hi,
Yep, you got it right...

.
Your input logic must be placed in the do statement so that it would be included in the loop...
cheers,
Paul June A. Domag