if

182.224.39.66 (토론)님의 2020년 5월 8일 (금) 09:17 판 (→‎CMD: .EQU.)

1 Bash

  다른 뜻에 대해서는 Bash if 문서를 참조하십시오.
He="John Smith"
if [ "$He" = "John Smith" ]; then
	echo "He is John Smith"
else
	echo "He is not John Smith"
fi
# He is John Smith

2 CMD

set my_name=John Smith
IF "%my_name%"=="John Smith" ECHO my_name is John Smith
set my_nam=10
IF "%my_nam%" LSS "11" ECHO 10은 11보다 작습니다.

지연된 환경 변수 확장을 사용하지 않을 경우 비교하는 문자열이 홀수 갯수의 쌍따음표를 포함하면 IF 문은 무조건 실패하므로 주의해야 한다.

쌍따음표로 문자열을 감싸는 것은 선택적인 사항이지만, 문자열이 비어있거나 이스케이핑이 필요한 문자를 포함할 경우(&와 같은 문자, 단 지연된 환경 변수 확장을 사용할 경우는 예외이다.) 무조건 실패한다.

3 Perl

if ( 43 > 42 ) {
	printf("hello\n");
	printf("world\n");
}

printf("hello\n") if (43 > 42);

4 PHP

if(43>42) {
	echo('hello');
	echo('world');
}
// helloworld
if(43>42) echo('hello');
// hello

5 Python

if 43 > 42:
	print('hello')
	print('world')
# hello
# world
if 43 > 42: print ('hello')
# hello

6 Ruby

if 43 > 42
	print 'hello'
end
# hello
  • one-line
print 'hello' if true
# hello
print 'world' if false

7 같이 보기

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}