If 편집하기

경고: 로그인하지 않았습니다. 편집을 하면 IP 주소가 공개되게 됩니다. 로그인하거나 계정을 생성하면 편집자가 사용자 이름으로 기록되고, 다른 장점도 있습니다.

편집을 취소할 수 있습니다. 이 편집을 되돌리려면 아래의 바뀐 내용을 확인한 후 게시해주세요.

최신판 당신의 편집
1번째 줄: 1번째 줄:
{{lowercase title}}
{{lowercase title}}


[[분류: 제어문]]
==Bash==
==Bash==
[[분류:Bash]]
[[category: Bash]]
{{다른뜻|Bash if}}
<source lang='bash'>
<syntaxhighlight lang='bash'>
He="John Smith"
He="John Smith"
if [ "$He" = "John Smith" ]; then
if [ "$He" = "John Smith" ]
then
echo "He is John Smith"
echo "He is John Smith"
else
else
13번째 줄: 12번째 줄:
fi
fi
# He is John Smith
# He is John Smith
</syntaxhighlight>
</source>
*[[Bash 숫자 비교]]


==C==
==Cmd==
[[분류: C]]
[[category: Cmd]]
{{참고|C if}}
<source lang='bash'>
<syntaxhighlight lang='c' run>
#include <stdio.h>
void main()
{
    if (43 > 42)
    {
        printf("hello\n");
    }
    else
    {
        printf("world\n");
    }
}
</syntaxhighlight>
 
==CMD==
[[분류:Cmd]]
<syntaxhighlight lang='bash'>
set my_name=John Smith
set my_name=John Smith
IF "%my_name%"=="John Smith" ECHO my_name is John Smith
IF "%my_name%"=="John Smith" ECHO my_name is John Smith
</syntaxhighlight>
</source>
<syntaxhighlight lang='bash'>
set my_nam=10
IF "%my_nam%" LSS "11" ECHO 10은 11보다 작습니다.
</syntaxhighlight>
* 지연된 환경 변수 확장을 사용하지 않을 경우 비교하는 문자열이 홀수 갯수의 쌍따음표를 포함하면 IF 문은 무조건 실패하므로 주의해야 한다.
* 쌍따음표로 문자열을 감싸는 것은 선택적인 사항이지만, 이 경우 문자열이 비어있거나 이스케이핑이 필요한 문자를 포함할 경우(&와 같은 문자, 단 지연된 환경 변수 확장을 사용할 경우는 예외이다.) 또는 문자열이 한개 이상의 띄어쓰기를 포함할 경우 무조건 실패한다.
 
==Perl==
[[분류:Perl]]
<syntaxhighlight lang='perl'>
if ( 43 > 42 ) {
printf("hello\n");
printf("world\n");
}
 
printf("hello\n") if (43 > 42);
</syntaxhighlight>


==PHP==
==PHP==
[[분류:PHP]]
[[category: PHP]]
{{참고|PHP if}}
<source lang='php'>
<syntaxhighlight lang='php'>
if(43>42) {
if(43>42) {
echo('hello');
echo('hello');
67번째 줄: 29번째 줄:
}
}
// helloworld
// helloworld
</syntaxhighlight>
</source>
<syntaxhighlight lang='php'>
<source lang='php'>
if(43>42) echo('hello');
if(43>42) echo('hello');
// hello
// hello
</syntaxhighlight>
</source>


==Python==
==Python==
[[분류:Python]]
[[category: python]]
{{참고|파이썬 if}}
<source lang='python'>
<syntaxhighlight lang='python' run>
if 43 > 42:
if 43 > 42:
print('hello')
print('hello')
print('world')
print('world')
</syntaxhighlight>
# hello
<syntaxhighlight lang='python' run>
# world
</source>
<source lang='python'>
if 43 > 42: print ('hello')
if 43 > 42: print ('hello')
</syntaxhighlight>
==Ruby==
[[분류:Ruby]]
<syntaxhighlight lang='Ruby'>
if 43 > 42
print 'hello'
end
# hello
</syntaxhighlight>
*one-line
<syntaxhighlight lang='Ruby'>
print 'hello' if true
# hello
# hello
print 'world' if false
</source>
</syntaxhighlight>


==같이 보기==
==See also==
* [[if ... else]]
*[[else]]
* [[else if]]
*[[else if]]
* [[switch]]
*[[true]]
* [[unless]]
*[[while]]
* [[true]]
*[[for]]
* [[while]]
*[[==]]
* [[for]]
* [[==]]
* [[ternary operator]]
* [[조건문]]
* [[제어문]]
* [[자바키워드]]

제타위키에서의 모든 기여는 크리에이티브 커먼즈 저작자표시-동일조건변경허락 3.0 라이선스로 배포된다는 점을 유의해 주세요(자세한 내용에 대해서는 제타위키:저작권 문서를 읽어주세요). 만약 여기에 동의하지 않는다면 문서를 저장하지 말아 주세요.
또한, 직접 작성했거나 퍼블릭 도메인과 같은 자유 문서에서 가져왔다는 것을 보증해야 합니다. 저작권이 있는 내용을 허가 없이 저장하지 마세요!

취소 편집 도움말 (새 창에서 열림)