Else if

else if
elseif
elif
elsif

1 Bash[편집]

A=2
if [ $A -eq 1 ]; then
    echo "A equals 1"
elif [ $A -eq 2 ]; then
    echo "A equals 2"
else
    echo "$?"
fi

2 CMD[편집]

@echo off
REM Windows 전용 문법임. 도스에는 ELSE IF가 없다.
set A=2
IF "%A%" == "1" (
    echo A equals 1
) ELSE IF "%A%" == "2" (
    echo A equals 2
) ELSE (
    echo $?
)

3 Perl[편집]

my $a = 2;
if ( $a eq 1 ) {
	print "a equals 1";
} elsif ( $a eq 2 ) {
	print "a equals 2";
} else {
	print "?";
}
# a equals 2

4 PHP[편집]

16px-Crystal_Clear_app_xmag.svg.png PHP elseif 문서를 참고하십시오.
$a = 2;
if( $a == 1 ) {
	echo "a equals 1";
} elseif( $a == 2 ) {
	echo "a equlas 2";
} else {
	echo "?";
}
# a equals 2
$a = 2;
if( $a == 1 ) {
	echo "a equals 1";
} else if( $a == 2 ) {
	echo "a equlas 2";
} else {
	echo "?";
}
$a = 2;
if( $a == 1 ):
	echo "a equals 1";
elseif( $a == 2 ):
	echo "a equlas 2";
else:
	echo "?";
endif;
$a = 2;
if( $a == 1 ) echo "a equals 1";
elseif( $a == 2 ) echo "a equlas 2";
else echo "?";
$a = 2;
if( $a == 1 ) echo "a equals 1";
else if( $a == 2 ) echo "a equlas 2";
else echo "?";

5 Python[편집]

a = 2
if a == 1:
	print("a equals 1");
elif a == 2:
	print("a equals 2");
else:
	print("?");
# a equals 2
a = 2
if a == 1: print("a equals 1");
elif a == 2: print("a equals 2");
# a equals 2

6 Ruby[편집]

a = 2
if a == 1
	puts "a equals 1"
elsif a == 2
	puts "a equals 2"
else
	puts "?"
end
# a equals 2
a = 2
if a == 1; puts "a equals 1"
elsif a == 2; puts "a equals 2"
else; puts "?"
end

7 같이 보기[편집]

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