일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
- Linux
- while
- instruction
- system
- computer
- Algorithm
- DB
- python
- CSS
- DS
- react
- MIPS
- mysql
- XML
- php
- control
- javascript
- function
- DoM
- data structure
- architecture
- Java
- DATAPATH
- Class
- html
- Pipelining
- web
- for
- github
- MacOS
- Today
- Total
목록while (8)
YYYEJI
do-while문이란? while문과 동일한데 do-while문은 조건이 true이든 false이든 최소한 한 번은 실행하고 조건문을 확인합니다. do { Action_code; } while (Boolean_Expression) public static void main(String[] args) { String month[] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}; int i = 0; do { System.out.println(month[i]); i++; } while (month[i]!="January"); } whi..
while문이란? 반복 횟수가 아닌 조건문으로 코드의 block을 반복시키고 싶을 때 사용하며, Sentinel-controlled loop 또는 counting loop라고도 불립니다. while (Boolean_Expression) { Action_code; } public static void main(String[] args) { String month[] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}; int i = 0; while (month[i]!="December") { System.out.println(month[..
** C code를 기준 ** 아래 코드를 MIPS assembly code로 변환해 보겠습니다. i = 0; while (a[i] == k) i++; C to MIPS assembly addi $s0, $zero, 0 # i = 0 loop: sll $t0, $s0, 2 # t0 = i*4 addi $t0, $t0, $s2 # t0 = t0 + &a[0] lw $t1, 0($t0) # t1 = a[t0] bne $t1, $s1 exit # if (t1 != s1) goto exit addi $s0, $s0, 1 # i = i + 1 j loop # goto loop exit: $s0 - i $s1 - k $s2 - a[0] 코드를 하나하나 살펴보면 addi $s0, $zero, 0 # i = 0 우선 ..
** C code를 기준 ** 아래 코드를 MIPS assembly code로 변환해 보겠습니다. switch (s) { case0: a = a case1: a = a + 1 case2: a + a + 2 default: a = a + 3 } C to MIPS assembly addi $t0, $zero, 1 # t0 = 1 addi $t1, $zero, 2 # t0 = 2 beq $s2, $zero, case0 # if (s == 0) goto case0 beq $s2, $t0, case1 # if (s == 1) goto case1 beq $s2, $t1, case2 # if (s == 2) goto case2 addi $s0, $zero, 3 # a = a + 3 j exit # goto exit ..
for문 반복 횟수가 정해진 경우 자주 사용됩니다. num = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] total = 0 for i in num: total += i print(total) while문 특정 조건이 만족할 때까지 반복문을 사용할 경우 자주 사용됩니다. i = 0 while i
반복문이란? 특정 조건을 만족할 때 같은 동작을 계속해서 반복하고자 할 때 사용합니다. Ex) for문, while문 etc . . . while : 반복할 문장 while문은 조건문이 참일 때 아래 코드를 수행합니다. Note) python에서 0은 false, 1은 true. 아래 코드는 i가 10보다 작거나 같으면 아래 문장을 수행하게 됩니다. i = 0 while i
continue - continue를 만나면 반복문의 다음 명령을 수행합니다. break - break를 만나면 반복문을 멈추고 loop 밖에 있는 명령을 수행합니다. 예제를 살펴봅시다. Continue 예제 i가 3일 때 다음 명령을 수행하라는 코드를 작성했습니다. 수행 결과를 보면 3을 제외한 숫자가 잘 출력된 것을 확인할 수 있습니다. for i in range(1, 6): if( i == 3): continue print(i) Break 예제 i가 3일 때 반복문을 멈추고 loop 밖에 있는 명령을 수행하라는 코드를 작성했습니다. 수행 결과를 보면 2까지 출력이 잘 되고, 3이 되는 순간 loop 밖에 명령을 수행한 것을 확인할 수 있습니다. for i in range(1, 6): if( i ==..
반복문이란? 특정 조건을 만족할 때 같은 동작을 계속해서 반복하고자 할 때 사용합니다. Ex) for문, while문 etc . . . for 변수 in range(시작, 끝-1, 증가폭): 반복할 코드 예제를 통해서 이해 해봅시다. range 함수 안에 숫자를 넣어주면 그 숫자-1 까지 증가하게 됩니다. 그 이유는 숫자가 1이 아닌 0부터 증가하기 때문입니다. 아래 코드는 0부터 9까지 출력하는 예제입니다. (코드와 같이 숫자를 넣어주면, 0부터 9까지 1씩 증가하게 됩니다.) for i in range(10): print(i) 아래 코드는 1부터 10까지 출력하는 예제입니다. (코드와 같이 숫자를 넣어주면, 1부터 10까지 1씩 증가하게 됩니다.) for i in range(1, 11): print(..