"Else"의 두 판 사이의 차이

 
(사용자 3명의 중간 판 13개는 보이지 않습니다)
1번째 줄: 1번째 줄:
[[분류: 제어문]]
;else
;else


==Bash==
==Bash==
[[category: Bash]]
[[category: Bash]]
<source lang='bash'>
<syntaxhighlight lang='bash'>
He="John Smith"
He="John Smith"
if [ "$He" = "John Smith" ]
if [ "$He" = "John Smith" ]; then
then
echo "He is John Smith"
echo "He is John Smith"
else
else
12번째 줄: 12번째 줄:
fi
fi
# He is John Smith
# He is John Smith
</source>
</syntaxhighlight>
 
==Go==
[[분류: Go]]
{{참고|Go if else}}
<syntaxhighlight lang='go' run>
package main
 
import "fmt"
 
func main() {
if 7%2 == 0 {
fmt.Println("7 is even")
} else {
fmt.Println("7 is odd")
}
 
if 8%4 == 0 {
fmt.Println("8 is divisible by 4")
}
 
if num := 9; num < 0 {
fmt.Println(num, "is negative")
} else if num < 10 {
fmt.Println(num, "has 1 digit")
} else {
fmt.Println(num, "has multiple digits")
}
}
</syntaxhighlight>
 
==PHP==
[[category: PHP]]
{{참고|PHP else}}
<syntaxhighlight lang='php'>
if ( 1 == 1 ) {
echo "True";
} else {
echo "False";
}
# True
</syntaxhighlight>
<syntaxhighlight lang='php'>
if ( 1 == 2 ):
echo "True";
else:
echo "False";
endif;
# False
</syntaxhighlight>


==Python==
==Python==
[[category: Python]]
[[category: Python]]
<source lang='python'>
<syntaxhighlight lang='python'>
if 1==1:
if 1==1:
print(True)
print(True)
22번째 줄: 71번째 줄:
print(False)
print(False)
# True
# True
</source>
</syntaxhighlight>
<source lang='python'>
<syntaxhighlight lang='python'>
if 1==2:
if 1==2:
print(True)
print(True)
29번째 줄: 78번째 줄:
print(False)
print(False)
# False
# False
</source>
</syntaxhighlight>
 
==Perl==
[[category: Perl]]
<syntaxhighlight lang='Perl'>
if ( 1 eq 1 ) {
print "True";
} else {
print "False";
}
# True
</syntaxhighlight>
<syntaxhighlight lang='Perl'>
if ( 1 eq 2 ) {
print "True";
} else {
print "False";
}
# False
</syntaxhighlight>
 
==Ruby==
[[category: Ruby]]
<syntaxhighlight lang='Ruby'>
if 43 > 42
puts 'true'
else
puts 'false'
end
# true
</syntaxhighlight>


==같이 보기==
==같이 보기==
*[[if]]
*[[if]]
*[[else if]]
*[[else if]]
 
*[[switch]]
==참고 자료==
*[[조건문]]
*http://eqcode.com/wiki/Else

2022년 3월 10일 (목) 11:43 기준 최신판

else

1 Bash[ | ]

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 Go[ | ]

package main

import "fmt"

func main() {
	if 7%2 == 0 {
		fmt.Println("7 is even")
	} else {
		fmt.Println("7 is odd")
	}

	if 8%4 == 0 {
		fmt.Println("8 is divisible by 4")
	}

	if num := 9; num < 0 {
		fmt.Println(num, "is negative")
	} else if num < 10 {
		fmt.Println(num, "has 1 digit")
	} else {
		fmt.Println(num, "has multiple digits")
	}
}

3 PHP[ | ]

if ( 1 == 1 ) {
	echo "True";
} else {
	echo "False";
}
# True
if ( 1 == 2 ):
	echo "True";
else:
	echo "False";
endif;
# False

4 Python[ | ]

if 1==1:
	print(True)
else:
	print(False)
# True
if 1==2:
	print(True)
else:
	print(False)
# False

5 Perl[ | ]

if ( 1 eq 1 ) {
	print "True";
} else {
	print "False";
}
# True
if ( 1 eq 2 ) {
	print "True";
} else {
	print "False";
}
# False

6 Ruby[ | ]

if 43 > 42
	puts 'true'
else
	puts 'false'
end
# true

7 같이 보기[ | ]

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