![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
|
break; help
Hey,
I'm just wondering, that if I wondered to break; from a switch that's inside a switch, would it go back to the previous switch? Consider this code (my own ^_^): /* Aviation program for Pilots
Created by Harry Wheildon */
using System;
class Avi {
public static void Main() {
char choice;
char std;
double speed;
double distance;
double time;
// Insert future variables here
for(;;) {
do {
Console.WriteLine("Choose one from the list:");
Console.WriteLine("1. Speed; Distance; Time");
Console.WriteLine("2. ISA Deviation");
Console.WriteLine("3. Time to Impact");
Console.WriteLine("4. Track Error; Closing Angle\n");
Console.Write("Choose one (press Q to quit): ");
do {
choice = (char) Console.Read();
} while(choice == '\n' | choice == '\r');
} while( choice < '1' | choice > '4' & choice != 'q');
if(choice == 'q') break;
Console.WriteLine("\n");
switch(choice) {
case '1':
Console.WriteLine("Here you can calculate the Speed, Distance or Time")
Console.WriteLine("Choose which one you want to calculate:")
Console.WriteLine("1. Speed")
Console.WriteLine("2. Distance")
Console.WriteLine("3. Time\n")
Console.Write("Choose one (press b to go back): ");
do {
std = (char) Console.Read();
} while(choice == '\n' | choice == '\r');
} while( choice < '1' | choice > '3' & choice != 'b');
if(choice == 'b') break;At the bottom break, if I pressed b in the actual program (not yet completed) would it go back to the previous switch menu? Thanks, Haz |
|
|
|
|
|
#2 |
|
Programming Guru
![]() ![]() ![]() |
The break; always sends control back to the code block that called it.
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
|
|
#3 |
|
Programmer
|
Thanks :-D
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|