StartprogrammingusingObjectPascal:KeyboardProgram

From 흡혈양파의 번역工房
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

키보드 프로그램

이 예제에서는 키보드로부터 문자를 받아서 프로그램이 키보드의 입력 받은 키에 대한 키보드의 줄 번호를 알려줄 것입니다.

var
    Key: Char;
begin
    Write('Please enter any English letter: ');
    Readln(Key);
    Writeln;

    case Key of
        'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p':
        Writeln('This is in the second row in keyboard');
        'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l':
        Writeln('This is in the third row in keyboard');
        'z', 'x', 'c', 'v', 'b', 'n', 'm':
        Writeln('This is in the fourth row in keyboard');
    else
        Writeln('Unknown letter');
    end;

    Write('Press enter key to close');
    Readln;
end.


참고로, case 조건문에 값 들의 집합이라는 새로운 기술을 사용했습니다.

'z', 'x', 'c', 'v', 'b', 'n', 'm':


이는 Key가 이 값들의 집합 (z, x, c, v, b, n, m) 중 하나라면 case 분기 구문을 실행한다는 의미입니다.


또한 다음과 같이 범위와 값을 혼용할 수 있습니다.

'a'.. 'd', 'x', 'y', 'z':


이는 값이 ad 사이에 있거나 x, y, z와 같을 경우 구문을 실행한다는 의미입니다.