「else if」って何気に言語ごとに違いありません?(elsifとか、elifとか、else ifとか)
個人的によく使う言語について改めて整理しました。
その2↓
Java(else if)
bash-4.2# javac -version javac 13.0.1 bash-4.2# cat Test.java public class Test{ public static void main(String[] args){ int val = Integer.parseInt(args[0]); if(val < 1){ System.out.println("val < 1"); }else if(val >= 1 && val < 3){ System.out.println("1 <= val <= 2"); }else{ System.out.println("val > 3"); } } } bash-4.2# javac Test.java bash-4.2# java Test 0 val < 1 bash-4.2# java Test 1 1 <= val <= 2 bash-4.2# java Test 3 val > 3
Python(elif)
[hoge@localhost tmp]$ python3 Python 3.6.8 (default, Aug 7 2019, 17:28:10) [hoge@localhost tmp]$ cat test.py # -*- coding: utf8 -*- import sys if __name__ == '__main__': val = int(sys.argv[1]) if val < 1: print("val < 1") elif val >= 1 and val < 3: print("1 <= val <= 2") else: print("val > 3") [hoge@localhost tmp]$ python3 test.py 0 val < 1 [hoge@localhost tmp]$ python3 test.py 1 1 <= val <= 2 [hoge@localhost tmp]$ python3 test.py 3 val > 3
Perl(elsif)
bash-4.2# perl -v This is perl 5, version 16, subversion 3 (v5.16.3) built for x86_64-linux-thread-multi bash-4.2# cat test.pl use strict; use warnings; use utf8; my $val = $ARGV[0]; if ($val < 1){ print "val < 1\r\n"; }elsif($val >= 1 && $val < 3){ print "1 <= val <= 2\r\n"; }else{ print "val > 3\r\n"; } bash-4.2# perl test.pl 0 val < 1 bash-4.2# perl test.pl 1 1 <= val <= 2 bash-4.2# perl test.pl 3 val > 3