본문 바로가기

전체28

5-4 continue & break "continue"와 "break"는 반복문 내에 삽입이 되어, 반복문의 실행 흐름을 조절하는데 사용됩니다. 먼저 break를 알아보겠습니다. break는 switch문을 빠져나갈때 사용된다고 먼저 설명을 드렸습니다. 마찬가지로 반복문을 빠져나가는 용도로도 사용되기도 합니다. 보통은 if문과 같이 사용이 되어서 특정한 조건을 만족하면 반복문을 빠져나가도록 사용을 합니다. public class BreakBasic {public static void main(String[] args) {int num=1;boolean search=false;while(num 2019. 3. 9.
5-3 for, while, do~while public class WhileBasic { public static void main(String[] args) {// TODO Auto-generated method stubint num = 0;while(num 2018. 10. 13.
5-2 switch / break switch문은 앞서 배운 if~else 문과 유사한 조건에 따라서 실행시킬 코드를 구분한다는 특징을 가지고 있습니다. public class SwitchBasic { public static void main(String[] args) {// TODO Auto-generated method stubint n = 3;switch(n) {case 1: System.out.println("Simple JAVA");case 2:System.out.println("Funny JAVA");case 3:System.out.println("Fantastic JAVA");default :System.out.println("The best programming language");}System.out.println("D.. 2018. 9. 17.
5-1 if~else if~else 문은 특정 조건이 만족될 때에만 실행하고 싶을때 사용합니다. 예를 들면 어떤 값일때 어떠한 명령을 수행시키고 싶다하면 if문의 괄호안에 그 조건을 넣으면 됩니다. public class IEBasic { public static void main(String[] args) {// TODO Auto-generated method stubif(true) {System.out.println("if & true");}if(false) {System.out.println("if~else & true");}else {System.out.println("if~else & false");}} } 이 코드의 실행 결과는 if & trueif~else & false 이렇게 나오게 됩니다. 조건이 참일때만 i.. 2018. 9. 16.