/ W3SCHOOLS

W3schools - Loop

이 페이지는 다음에 대한 공부 기록입니다
Lecture에서 배웠던 내용을 복습하며 작성했습니다

찾으시는 정보가 있으시다면
주제별reference를 이용하시거나
우측 상단에 있는 검색기능을 이용해주세요

Java while Loop

Loops can execute a block of code as long as a specified condition is reached

while(condition){
  code block
}

Don’t forget to increase the variable used in the condition, otherwise the loop will never end

Do / while Loop

Is a variant of the while loop

This loop execute the code block once before checking if the condition is true

do{
  code block
}while(condition);

Java For Loop

Use “for” when you know exactly how many times you want to loop through a block of code

for(S1;S2;S3){
  code block
}

S1 is executed (once) before the execution of the code block

S2 defines the condition for executing the code block

S3 is executed(everytime) after the code block has been executed

For-Each Loop

for(type variableName : arrayName){
  code block
}

It is used exclusively to loop through elements in an array

Java Break and Continue

“break” statement can be used to jump out of a loop

“continue” statement breaks one iteration(in the loop)

  • if a specified condition occurs and continues with the next iteration