C#/C# 연습

for, While : Buger (버거)

HicKee 2022. 11. 28. 13:57

for(; ;)

무한 반복으로 사용

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace pr_conditional {
    internal class Program {
        static void Main(string[] args) {

            for(; ;) {
                Console.WriteLine();
                Console.WriteLine("MENU");
                Console.WriteLine();
                Console.WriteLine("1.치즈버거");
                Console.WriteLine("2.치킨버거");
                Console.WriteLine("3.빅맥버거");
                Console.WriteLine("Q 종료");
                Console.WriteLine("선택 : ");
                string input = Console.ReadLine(); ;

                if (input == "Q" || input == "q") {
                    Console.WriteLine("종료합니다.");
                    Environment.Exit(0);
                }
                else if(input == "1") {
                    Console.WriteLine("치즈버거를 선택");
                }
                else if (input == "2") {
                    Console.WriteLine("치킨버거를 선택");
                }
                else if (input == "3") {
                    Console.WriteLine("빅맥버거를 선택");
                }
                else {
                    Console.WriteLine("오류가 발생");
                }
            }
        }
    }
}

while

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace pr_conditional {
    internal class Program {
        static void Main(string[] args) {
           
            while (true) {

                Console.WriteLine("번호를 선택하세요");

                string input  = Console.ReadLine();

                switch (input) {
                    case "1":
                        Console.WriteLine("1번 선택");
                        break;
                    case "2":
                        Console.WriteLine("2번 선택");
                        break;
                    case "3":
                        Console.WriteLine("3번 선택");
                        break;
                    case "q":
                        Console.WriteLine("q번 선택");
                        break;
                    case "Q":
                        Console.WriteLine("Q번 선택");
                        break;
                    default:
                        break;
                }
            }
        }
    }
}

'C# > C# 연습' 카테고리의 다른 글

Array : Input, MaxMin (입력, 최대값 최소값)  (0) 2022.11.29
Array : Length input, Random (배열수 입력, 난수)  (0) 2022.11.28
Operation : 연산자  (0) 2022.11.28
Data Type Casting : 자료형 변환  (0) 2022.11.27
입력  (0) 2022.11.27