15-10. 반복문
https://www.opentutorials.org/course/1688/9374
반복문
- 조건이 false가 될 때까지 반복
무한루프
- 프로그래밍을 하는 과정에서 생길 수 있는 큰 에러 중의 하나
- 조건에 true를 때려박는 경우
- 작업이 너무 헤비(heavy)하면 무한루프인 것 같은 상황에 빠질 수도 있다.
<br />
- HTML에서 줄바꿈이라는 의미의 태그
9.php
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 | <!DOCTYPE html> <html> <head> <meta charset = "utf-8"> </head> <body> <h1>javascript</h1> <ul> <script charset="utf-8"> i = 0; while(i < 3){ document.write("<li>hello world</li>"); i = i +1; } </script> </ul> <h1>PHP</h1> <ul> <?php $i = 0; while($i < 3){ echo "<li>hello world</li>"; $i = $i +1; } ?> </ul> </body> </html> | cs |
15-11. 배열
https://www.opentutorials.org/course/1688/9375
배열(Array)
- 서로 연관되어 있는 여러 정보들을 연속된 그릇에 담아서 체계적으로 관리하는 도구
10.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | <!DOCTYPE html> <html> <head> <meta charset = "utf-8"> </head> <body> <h1>javascript</h1> <script charset="utf-8"> list = new Array("one", "two", "three"); document.write(list[0]); // list라는 변수에 담겨있는 배열의 0번째 값 = one document.write(list.length); // 배열의 길이 </script> <h1>PHP</h1> <?php $list = array("one", "two", "three", "four"); echo $list[2]; // list라는 변수에 담겨있는 배열의 2번째 값 = three echo count($list); // 배열의 길이 ?> </body> </html> | cs |
※ 배열 + 반복문
11.php
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 29 30 31 32 | <!DOCTYPE html> <html> <head> <meta charset = "utf-8"> </head> <body> <h1>javascript</h1> <ul> <script charset="utf-8"> list = new Array("일", "이", "삼", "사", "오"); i = 0; while(i < list.length){ // 배열의 길이만큼 반복 document.write("<li>"+list[i]+"</li>"); i = i + 1; } </script> </ul> <h1>PHP</h1> <ul> <?php $list = array("일", "이", "삼", "사"); $i = 0; while($i < count($list)){ // 배열의 길이만큼 반복 echo "<li>".$list[$i]."</li>"; $i = $i + 1; } ?> </ul> </body> </html> | cs |
'컴퓨터 > 웹 개발' 카테고리의 다른 글
[코딩야학] ~ JS실습 - 11,12일차 (0) | 2017.08.02 |
---|---|
[코딩야학] ~ 프로그래밍 접근방법 - 10일차 (0) | 2017.08.01 |
[코딩야학] ~ 로그인기능 - 8일차 (0) | 2017.07.31 |
[코딩야학] ~ 조건문 - 7일차 (0) | 2017.07.31 |
[코딩야학] ~ 웹페이지에 코드삽입 - 6일차 (0) | 2017.07.31 |