/ W3SCHOOLS

W3schools - Conditional

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

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

Java Booleans

Boolean expression : returns a Boolean value(true o false)

Can use a comparision operator

Java if-else

“if”

  • to specify a block of code to be executed

  • if a specified condition is true

“else”

  • if a same condition is false

“else if”

  • new condition to test if the first false

short hand if-else(Ternary Operator)

variable = (condition) ? expressionTrue : expressionFalse
  • why “ternary”?

    • because it consists of three operands

“switch”

  • to specify many alternative blocks of code to be executed

Switch

switch(expression){     //evaluated once
case x:     //The value of expression is compared with the values of each case
  code block
  break;    //Java reaches a “break” keyword, it breaks out of the switch block, it ignores the execution of all the rest of the code in the switch block
case y:
  code block
  break;
default:    //if there is no case match, associated block of code is executed
  code block
}