Else if

(Elseif에서 넘어옴)
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[ | ]

$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 }}