| Previous Post | Top | Next Post |
TOC
This was originally written and created around 2013 and may require to be updated. (2021)
Language basics
See Wikipedia article on programing language.
Please note this may be inaccurate.
- statement
;as statement terminator: C, C++, Java, Vala, …;as statement separator: Perl, Pascal, PL/I, SQL, …- EOL as statement terminator: Python
;or EOL as statement terminator: Shell;as NOP statement: Lua
- block statement
{statement...}: C, C++, Java, Vala, Perl, Shell, Lua, …BEGINstatement...END: Pascal- indented block : Python
- comment
/* ... */or// ...: C, C++, Java, Vala# ...: Perl, Python, Shell-- ...or--[[ ... ]]: Lua (line and block comment)
- character constant
'a': C, C++
- string
"abcdef": C, C++, Vala, Python, Perl, Lua; Shell(subst)'abcdef': Python, Perl, Lua; Shell(non-subst.)"""abcdef""": Vala, Python (string literals that span multiple lines)[==[abcdef]==]: Lua (string literals that span multiple lines)
- string concatenate operator
.: Perl..: Lua+: Vala, Python, Pascal- put together side by side: Shell
- call some function: C (think about glib)
- modulo
%: C, C++, Vala, Python, Perl, Luamod: Pascal
- floor
//: Pythondiv: Pascal
- power operator
**: Python, Perl^: Lua- use
pow(...)function : C, C++, Vala
- bit not operator
~: C, C++, Vala, Python, Perl
- bit or operator:
|: C, C++, Vala, Python, Perl
- bit and operator:
&: C, C++, Vala, Python, Perl
- bit exclusive-or operator:
^: C, C++, Vala, Python, Perl
- logical not operator
!: C, C++, Vala, Shell, Perlnot: Python, Lua
- logical or operator:
|: Python||: C, C++, Vala, Perl, Shellor: Lua
- logical or operator:
&: Python&&: C, C++, Vala, Perl, Shelland: Lua
if– triple choices as exampleif(...){statement...}elseif(...){statement...}else{statement...}` : C, C++, Vala, Javaif...:statement...elif...:statement...else:statement...: Python (multilined and indented)if(...){statement...}elsif(...){statement...}else{statement...}: Perlif...thenstatement...elseif...thenstatement...elsestatement...end: Luaif[...];thenstatement; ...elif[...];statement; ...elsestatement; ...fi: Shell
- for – indexed loop
for (i = 1; i <= n; i++){statement...}: C, C++, Vala, Javafor i in range(1,n):statement...: Python (multilined and indented)for ($i = 1; $i <= $n; $i++){statement...}: Perlfor i=1, n, 1dostatement...end: Lua
- foreach – iterator loop
for (type &i : items){statement...}: C++11foreach (type i in items){statement...}: Valafor (type i : items){statement...}: Javafor i in items:statement...: Python (multilined and indented)foreach $i (@items){statement...}: Perlfor i in items ... ;dostatement; ...done: Shell
- while loop
while(loop_true){statement...}: C, C++, Vala, Java, Perlwhileloop_true:statement...: Python (multilined and indented)while(loop_true)dostatement...end: Luawhile[...];dostatement; ...done: Shell
- do while loop
do{statement...}while(loop_true);: C, C++, Vala, Java, Perlwhile true:statement...if!loop_true:break: Python (multilined and indented)repeatstatement...until!loop_true: Lua
break- supported : C, C++, Vala, Java, Python, Lua, Shell
- Instead, use
last: Perl
continue- supported : C, C++, Vala, Java, Python, Shell
- Instead, use
next: Perl - NOT supported : Lua (Use
ifto skip the rest.)
return- supported : C, C++, Vala, Java, Python, Lua, Shell
- multiple branching
switch(c){case 'a':statement…break;default:statement...}: C, C++, Vala, Javacase$xina)statement;...;;?)statement;...;;esac: Shell- NOT supported. Use
if ...: Perl, Python, Lua
Both return and exit are used for similar purposes for many languages.
- C :
exitis a function in thelibclibrary.- when
exitis called, it terminates the process.
- when
- C :
returnis a reserved keyword of the C language.- when
returnis in themain()function, it terminates the process. - when
returnis not in themain()function, it returns to the calling function code.
- when
- Shell :
exitis a builtin.- when
exitis called, it terminates the shell code.
- when
- Shell :
returnis a builtin.- when
returnis in the main shell code, it terminates the main shell code. - when
returnis in the block code{ ...; }, it terminates the main shell code. - when
returnis in the subshell( ...; ), it returns to the main shell code. - when
returnis in the sourced file, it returns to the sourcing shell code.
- when
For the C++ language, you need to be careful uing exit in main() since no
destructor will be called for the locally scoped objects for exit.
| Previous Post | Top | Next Post |