Codegym University 과정의 일부로 멘토와 함께하는 강의 스니펫. 전체 과정에 등록하십시오.


"안녕."

"안녕, 엘리!"

" 루프에 대해 배울 시간 입니다 . 루프는 if/else 문만큼 간단하지만 훨씬 더 흥미롭습니다. 루프를 사용하여 명령 또는 명령 블록을 여러 번 실행할 수 있습니다. 일반적으로 루프는 다음과 같습니다."

루프(예시 1)
while(boolean condition)
    command;
루프(예제 2)
while(boolean condition)
    block of commands in curly brackets

"모든 것이 매우 간단합니다. 루프 조건이 참인 한 명령이나 블록이 반복해서 실행됩니다. 먼저 조건을 확인합니다. 조건이 참이면 루프 본문(명령 블록)이 실행됩니다. 조건은 다시 확인합니다. 조건이 참이면 루프 본문이 다시 실행됩니다. 조건이 참이 아닐 때까지 반복됩니다."

"항상 참이거나 항상 거짓이라면?"

"항상 참이면 프로그램이 실행을 멈추지 않습니다. 루프를 무한정 반복합니다. 항상 거짓이면 루프 본문이 실행되지 않습니다."

여기 몇 가지 예가 있어요.

자바 코드 설명
int i = 3;
while (i >= 0)
{
    System.out.println(i);
    i--;    //Decrease by 1
}
3
2
1
0
int i = 0;
while (i < 3)
{
    System.out.println(i);
    i++;   //Increase by 1
}
0
1
2
boolean isExit = false;
while (!isExit)
{
    String s = buffer.readLine();
    isExit = s.equals("exit");
}
프로그램은 문자열 'exit'가 입력될 때까지 키보드에서 문자열을 인쇄합니다 .
while (true)
    System.out.println("C");
프로그램은 화면에 문자 C를 반복해서 표시합니다 .
while (true)
{
    String s = buffer.readLine();
    if (s.equals("exit"))
        break;
}
프로그램은 문자열 'exit'가 입력될 때까지 키보드에서 문자열을 읽습니다 .
2
과제
Java Syntax,  레벨 4레슨 8
잠금
Code entry
Your attention, please! Now recruiting code entry personnel for CodeGym. So turn up your focus, let your fingers relax, read the code, and then... type it into the appropriate box. Code entry is far from a useless exercise, though it might seem so at first glance: it allows a beginner to get used to and remember syntax (modern IDEs seldom make this possible).

"조건문 이후로는 복잡해 보이지 않습니다. 벌써 해보고 싶어요."