내용으로 건너뛰기
권남
사용자 도구
로그인
사이트 도구
검색
도구
문서 보기
이전 판
역링크
최근 바뀜
미디어 관리자
사이트맵
로그인
>
최근 바뀜
미디어 관리자
사이트맵
추적:
groovy:제어문
이 문서는 읽기 전용입니다. 원본을 볼 수는 있지만 바꿀 수는 없습니다. 문제가 있다고 생각하면 관리자에게 문의하세요.
====== Groovy 제어문 ====== * [[http://groovy.codehaus.org/Control+Structures|Groovy Control Structure]] * http://groovy.codehaus.org/JN2535-Control * [[http://groovy.codehaus.org/Looping|Groovy Looping]] ===== for ===== * for 문은 거의 사용할 일이 없다. * Index가 필요한 for 문은 ''list.eachWithIndex { obj, idx -> 처리문... }'' 형태로 만들면 된다.<code groovy> def stringList = [ "java", "perl", "python", "ruby", "c#", "cobol", "groovy", "jython", "smalltalk", "prolog", "m", "yacc" ] stringList.eachWithIndex() { obj, i -> println " ${i}: ${obj}" } </code> ===== switch/case ===== * case 에는 ''isCase()'' 구현체 아무것이나 와도 된다. ''1..10'' 형태의 Range도 isCase()를 구현하고 있다. * [[http://ndpar.blogspot.kr/2011/06/functional-groovy-switch-statement.html|Functional Groovy switch statement]]<code groovy> class CaseCategory { static boolean isCase(Closure casePredicate, Object switchParameter) { casePredicate.call switchParameter } } use (CaseCategory) { switch (param) { case { it % 2 == 0 } : return 'even' case { it % 3 == 0 } : return 'threeven' case { 0 < it } : return 'positive' default : return 'negative' } } </code>
groovy/제어문.txt
· 마지막으로 수정됨: 2013/05/17 14:50 저자
kwon37xi
문서 도구
문서 보기
이전 판
역링크
맨 위로