반응형
1. 조건문 (Conditional Statements)if 문if문은 조건이 참일 때 특정 블록의 코드를 실행합니다.public class Conditional { public static void main(String[] args) { int number = 10; if (number > 0) { System.err.println("양수"); } }}if-else 문조건이 참일 때와 거짓일 때 각각 다른 블록의 코드를 실행합니다.public class Ifel { public static void main(String[] args) { // if-else 문 int number = -5; ..
Go 언어에서 제어 구조와 흐름 제어를 이해하는 것은 프로그래밍의 기본으로, if문과 switch, for 반복문이 있습니다.1. if 문if 문은 조건에 따라 코드 블록을 실행할 수 있습니다.package mainimport "fmt"func main() { x := 20 if x > 10 { fmt.Println("x가 10보다 큼") } else { fmt.Println("x가 5보다 작거나 같음") }}2. switch 문switch 문은 여러 조건을 처리할 때 유용하며, 여러 개의 case를 사용할 수 있습니다.package mainimport "fmt"func main() { day := 2 switch day { case 1: fmt.Println("월요일") case 2: fmt..
1. if 문파이썬의 if문은 자바스크립트 언어와 비슷한 형식으로 사용합니다.x = int(input("Please enter an integer: "))# Please enter an interger: 1if(x 숫자가 없거나 여러 개의 elif 문이 있고 else는 그 안에 원하는 숫자가 없을 경우 입니다. elif는 else if를 줄인 표현식으로 과도한 드령쓰기 방지에 유용합니다. 2.for문파이썬에서 for문은 C언어나 파스칼에서 사용하는 방식과 약간 다릅니다. sports = ['football', 'baseball', 'cricket'];for w in sports: print(w, len(w))''' football 8baseball 8cricket 7''' 컬렉션을 이터레이트 ..