3일차 줄넘기를 하려면 D키를 입력 해주세요. (4) d키를 입력받지 않으면 처음으로 돌아간다.

Console Programming/C# Console 2019. 9. 20. 17:10
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace Syntax06
{
    class Program
    {
        static void Main(string[] args)
        {
            Restart:
            Console.WriteLine("줄넘기를 하려면 D 키를 입력 해주세요.");
            ConsoleKeyInfo info = Console.ReadKey();
            bool condition = info.KeyChar == 'd';
            
            if (condition)
            {
                Console.Write("몇회 줄넘기를 할건가요? ");
                int count = Int32.Parse(Console.ReadLine());
 
                Console.Clear();
 
                for (int i = 1; i < count+1; i++)
                {
                    Console.Write("줄넘기를 ");
                    if (i % 2 == 1)
                    {
                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.Write(i);
                        Console.ResetColor();
                    }
                    else
                    {
                        Console.Write(i);
                    }
 
                    Console.Write("회 했습니다.");
                    if (i%3 == 0)
                    {
                        Console.WriteLine(" (\"야호!\")" );
                    }
                    else
                    {
                        Console.WriteLine();
                    }
                }
                
            }
            else
            {
                Console.Clear();
                goto Restart;
 
             }
        }
    }
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

goto를 사용하여 레이블 지정된 문으로 직접 프로그램 컨트롤을 전송합니다.

Restart라는 레이블로 지정된 곳으로 이동한다.

 

d를 누르고 10을 입력하면 줄넘기를 10회 한다.

 

d가 아닌 키를 누르면 처음으로 돌아간다.

 

: