Comparison of programming languages (basic instructions): Difference between revisions

Content deleted Content added
m Loop statements: <nowiki>s supress BracketBot's warning
Tag: nowiki added
Line 1,752:
| rowspan=9|<tt>'''while ('''condition''')''' '''{''' instructions '''}'''</tt>
| rowspan=9|<tt>'''do {''' instructions '''} while ('''condition''')'''</tt>
| rowspan=5|<tt>'''for ('''«type» i '''=''' first''';''' i '''<nowiki><=</nowiki>''' last'''; ++'''i''') {''' instructions '''}'''</tt>
| {{n/a}}
|-
Line 1,769:
|-
| JavaScript
|<tt>'''for (var''' i '''=''' first''';''' i '''<nowiki><=</nowiki>''' last''';''' i'''++) {''' instructions '''}'''</tt>
|<tt>'''for (var''' index '''in''' set''') {''' instructions '''}''' <br/> or <br/> '''for each (var''' item '''in''' set''') {''' instructions '''}'''</tt> (JS 1.6+, deprecated<ref>https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Statements/for_each...in</ref>)<br/>or<br/><tt>'''for (var''' item '''of''' set''') {''' instructions '''}'''</tt> ([[EcmaScript 6]] proposal, supported in Firefox<ref>https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Statements/for...of</ref>)
|-
Line 1,787:
| <tt>'''for '''condition''' {''' instructions '''}'''</tt>
|
| <tt>'''for '''i ''':=''' first''';''' i '''<nowiki><=</nowiki>''' last'''; '''i'''++ {''' instructions '''}'''</tt>
| <tt>'''for '''key''', '''item''' := range '''set''' {''' instructions '''}'''</tt>
|-
Line 1,799:
| <tt>'''while''' condition '''{''' instructions '''}''' or <br/> '''until''' notcondition '''{''' instructions '''}'''</tt>
| <tt>'''repeat {''' instructions '''} while '''condition or <br/> '''repeat {''' instructions '''} until''' notcondition</tt>
| <tt>'''for''' first'''..'''last '''<nowiki>-></nowiki> $i {''' instructions '''}''' or <br/> '''loop ($i = '''first'''; $i <nowiki><= </nowiki>'''last'''; $i++) {''' instructions '''}'''</tt>
| <tt>'''for''' set« '''<nowiki>-></nowiki>''' $item» '''{''' instructions '''}'''</tt>
|-
| Ruby
Line 1,811:
| <tt>'''while''' condition ;'''do'''<ul>instructions</ul>'''done''' <br/> or <br/> '''until''' notcondition ;'''do'''<ul>instructions</ul> '''done'''</tt>
| {{n/a}}
| <tt>'''for (('''i '''=''' first''';''' i '''<nowiki><=</nowiki>''' last'''; ++'''i''')) ; do'''
<ul>instructions</ul>
'''done'''
Line 1,820:
| <tt>'''while ('''condition''')''' '''{''' instructions '''}'''</tt>
| <tt>'''do {''' instructions '''} while ('''condition''')'''</tt>
| <tt>'''for ('''i '''<nowiki><-</nowiki>''' first '''to''' last «'''by 1'''»''') {''' instructions '''}'''<br/>or<br/>first '''to''' last «'''by 1'''» '''foreach ('''i '''<nowiki>=></nowiki> {''' instructions '''})'''</tt>
| <tt>'''for ('''item '''<nowiki><-</nowiki>''' set''') {''' instructions '''}'''<br/>or<br/>set '''foreach ('''item '''=> {''' instructions '''})'''</tt>
|-
| Smalltalk
Line 1,832:
| <tt>'''(loop<ul>while '''condition'''</ul><ul>do</ul><ul>'''instructions''')'''</ul> or <br/> '''(do () ('''notcondition''')<ul>'''instructions''')'''</ul></tt>
| <tt>'''(loop<ul>do</ul><ul>'''instructions'''</ul><ul>while '''condition''')'''</ul></tt>
| <tt>'''(loop<ul>for i from '''first''' to '''last''' «by 1»</ul><ul>do</ul><ul>'''instructions''')'''</ul> or <br/> '''(dotimes (i N)'''<ul>instructions''')'''</ul> or<br/> '''(do ((i '''first''' (1+ i))) ((<nowiki>>=</nowiki> i '''last'''))<ul>'''instructions''')'''</ul></tt>
| <tt>'''(loop<ul>for '''item''' in '''set'''</ul><ul>do</ul><ul>'''instructions''')'''</ul> or <br/> '''(dolist ('''item set''')<ul>'''instructions''')'''</ul> or <br/>'''(mapc '''function list''')''' or <br/> '''(map <nowiki>'</nowiki>'''type function sequence''')'''</tt>
|-
Line 1,838:
| <tt>'''(do () ('''notcondition''') '''instructions''')''' or <br/> '''(let loop () (if '''condition''' (begin '''instructions''' (loop))))'''</tt>
| <tt>'''(let loop () ('''instructions''' (if '''condition''' (loop))))'''</tt>
| <tt>'''(do ((i '''first''' (+ i 1))) ((<nowiki>>=</nowiki> i '''last''')) '''instructions''')''' or <br/> '''(let loop ((i '''first''')) (if (< i '''last''') (begin '''instructions''' (loop (+ i 1)))))'''</tt>
| <tt>'''(for-each (lambda ('''item''') '''instructions''') '''list''')'''</tt>
|-
Line 1,844:
| <tt>'''(while '''condition''' '''instructions''')'''</tt>
| <tt>'''(tagbody loop''' instructions '''(if''' condition '''(go loop))'''</tt>
| <tt>'''(for ((i '''first''' (+ i 1))) ((<nowiki>>=</nowiki> i '''last''')) '''instructions''')'''</tt>
| <tt>'''(mapc (lambda ('''item''') '''instructions''') '''list''')'''</tt>
|-
Line 1,866:
| <tt>'''while''' condition ''':''' <br/> {{keypress|Tab}} instructions <br/> «'''else:''' <br/> {{keypress|Tab}} instructions»</tt>
| {{n/a}}
| <tt>'''for i in range('''first''', '''last'''):''' <br/> {{keypress|Tab}} instructions <br/> «'''else:''' <br/> {{keypress|Tab}} instructions»</tt>(Python 1.x and 3.x)<br/>
<tt>'''for i in xrange('''first''', '''last'''):''' <br/> {{keypress|Tab}} instructions <br/> «'''else:''' <br/> {{keypress|Tab}}instructions»</tt>(Python 2.x)
| <tt>'''for''' item '''in''' set''':''' <br/> {{keypress|Tab}} instructions <br/> «'''else:''' <br/> {{keypress|Tab}} instructions»</tt>
Line 1,873:
| <tt>'''while ('''condition''') {''' instructions '''}''' «'''then''' optional-block»</tt>
| <tt>'''do {''' instructions '''} while ('''condition''')''' «'''then''' optional-block»</tt>
| <tt>'''for (i = '''first'''; i <nowiki><</nowiki> '''last'''; i++) {''' instructions '''}''' «'''then''' optional-block»</tt>
| <tt>'''foreach''' item'''('''set''')''' «'''using ('''what''')'''» '''{''' instructions '''}''' «'''then''' optional-block»</tt>
|-
Line 1,892:
| {{n/a}}
| <tt>'''for i = '''first''' to '''last'''-1 do''' instructions '''done'''</tt>
| <tt>'''Array.iter (fun '''item''' <nowiki>-></nowiki> '''instructions''') '''array <br/> '''List.iter (fun '''item''' -> '''instructions''') '''list</tt>
|-
| F#
Line 1,903:
| <tt>'''while''' condition '''do (''' instructions ''')'''</tt>
| colspan=2 {{n/a}}
| <tt>'''Array.app (fn '''item''' <nowiki>=></nowiki> '''instructions''') '''array <br/> '''app (fn '''item''' => '''instructions''') '''list</tt>
|-
| Haskell (GHC)
| colspan=2 {{n/a}}
| <tt>'''Control.Monad.forM_ [0..N-1] (\i <nowiki>-></nowiki> do '''instructions''')'''</tt>
| <tt>'''Control.Monad.forM_ '''list '''(\item <nowiki>-></nowiki> do '''instructions''')'''</tt>
|-
| Eiffel