Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace ConsoleApp3
- {
- class Program
- {
- static void Main(string[] args)
- {
- while(true)
- {
- Console.Clear();
- Console.WriteLine("Press 1 or 2 to perform operation. Press any other key to exit");
- Console.WriteLine("1. All digits from highest to lowest using while");
- Console.WriteLine("2. All digits from highest to lowest using for");
- var key = Console.ReadKey();
- if (key.Key == ConsoleKey.D1)
- {
- DigitsUsingWhile();
- }
- else if (key.Key == ConsoleKey.D2)
- {
- DigitsUsingFor();
- }
- else
- {
- return;
- }
- }
- }
- static void DigitsUsingWhile()
- {
- Console.Clear();
- Console.WriteLine("Writing digits from highest to lowest using while loop");
- int i = 9;
- while(i >= 0)
- {
- Console.WriteLine(i);
- i--;
- }
- AfterLoop();
- }
- static void DigitsUsingFor()
- {
- Console.Clear();
- Console.WriteLine("Writing digits from highest to lowest using for loop");
- for (int i = 9; i >= 0; i--)
- {
- Console.WriteLine(i);
- }
- AfterLoop();
- }
- static void AfterLoop()
- {
- Console.WriteLine("Press any key to return to menu");
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement