Java Programming
Would you like to react to this message? Create an account in a few clicks or log in to continue.


here you can ask help for your java related problems
 
HomeLatest imagesSearchRegisterLog in

 

 1st year students read and study this GoTo command

Go down 
AuthorMessage
Ak
Java Freak
Java Freak
Ak


Posts : 23
Join date : 2009-02-07

1st year students read and study this GoTo command Empty
PostSubject: 1st year students read and study this GoTo command   1st year students read and study this GoTo command EmptySat Feb 09, 2013 1:57 am

Code:

using System;
using System.Collections;
using System.Linq;
using System.Text;

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
            string myInput;
      int myInt;

      begin: // <----- notice the begin here once we type continue this program will jump back here and read the below code again

      Console.Write("Please enter a number between 1 and 3: ");
      myInput = Console.ReadLine();
      myInt = Int32.Parse(myInput);

      // Switch with integer type
      switch (myInt)
      {
        case 1:
            Console.WriteLine("Your number is {0}.",myInt);
            break;
        case 2:
            Console.WriteLine("Your number is {0}.",myInt);
            break;
        case 3:
            Console.WriteLine("Your number is {0}.",myInt);
            break;
        default:
            Console.WriteLine("Your number {0} is not between 1 and 3.",myInt);
            break;
      }

      decide: // <--- if your input was incorrect this will be triggered

      Console.Write("Type\"continue\"to go on or\"quit\"to stop: "); 
      myInput = Console.ReadLine();

      // switch with string type
      switch (myInput)
      {
        case "continue":
            goto begin; // <---- goto command is use to jump from statements to another statement but this is not a good programming practice
        case "quit":
            Console.WriteLine("bye.");
            break;
        defualt:
            Console.WriteLine("Your input {0} is incorrect.",myInput);
            goto decide; // <-- same here i use goto to make this program student friendly
      }
        }
    }
}

Back to top Go down
https://javafreak.board-directory.net
 
1st year students read and study this GoTo command
Back to top 
Page 1 of 1
 Similar topics
-
» Data Struc students read and study
» read file from notepad using c#
» Data Struc completion project read this

Permissions in this forum:You cannot reply to topics in this forum
Java Programming :: Programming :: C# Programming-
Jump to: