|
Nesting Conditional Statements |
|
|
This is an example of writing a conditional statement inside of another, which is referred to as nesting: |
using System;
class NewProject
{
static void Main()
{
char SittingDown;
string SitDown;
do
{
Console.Write("Are you sitting down now(y/n)? ");
SitDown = Console.ReadLine();
SittingDown = char.Parse(SitDown);
if( SittingDown != 'y' )
Console.WriteLine("Could you please sit down for the next exercise?");
}while( SittingDown != 'y' );
Console.WriteLine("Wonderful. Now we will continue today's exercise...");
Console.WriteLine("\n...\nEnd of exercise\n");
char WantToContinue;
Console.Write("\nDo you want to continue(1=Yes/0=No)? ");
string ToContinue = Console.ReadLine();
WantToContinue = char.Parse(ToContinue);
if(WantToContinue == '1')
{
char LayOnBack;
Console.WriteLine("Good. For the next exercise, you should lay on your back");
Console.Write("Are you laying on your back(1=Yes/0=No)? ");
string Lay = Console.ReadLine();
LayOnBack = char.Parse(Lay);
if(LayOnBack == '0')
{
char Ready;
do
{
Console.WriteLine("Please lay on your back");
Console.Write("\nAre you ready(1=Yes/0=No)? ");
string R = Console.ReadLine();
Ready = char.Parse(R);
}while(Ready == '0');
}
else if(LayOnBack == '1')
Console.WriteLine("\nGreat.\nNow we will start the next exercise.");
else
Console.WriteLine("\nWell, it looks like you are getting tired...");
}
else
Console.WriteLine("\nWe had enough today");
Console.WriteLine("\nWe will stop the session now\nThanks.\n");
}
}
|
|
| Copyright © 2004 FunctionX, Inc. |
|
|