If Else Statements

윤년
윤년 Vim script에서
function! LeapYear(year) abort
  if a:year % 400 == 0 
    return 1
  elseif a:year % 100 == 0
    return 0
  elseif a:year % 4 == 0
    return 1
  else
    return 0
  endif
endfunction

The if, elseif, and else statements are the core of branching code execution in Vim script. The clauses for each are checked sequentially until one produces a truthy value. Each clause checks if a year is evenly divisible by another number by checking the remainder of their division. If a year is evenly divisible by 400, the first clause produces a truthy value so the command within the if branch is executed, returning 1. If it's not evenly divisible, Vim proceeds to the next clause until one produces a truthy value or the else statement is hit. In that case, 0 is returned because the year failed all three checks.

2026년 09월 23일 · 유용했나요?

Vim script의 윤년에 대한 다른 접근법

우리 커뮤니티가 이 연습 문제를 해결한 다른 방법