Loops/Downward for: Difference between revisions
Content added Content deleted
m (Added a Trith example.) |
(→{{header|Ada}}: Added 6502 Assembly) |
||
Line 2: | Line 2: | ||
Write a for loop which writes a countdown from 10 to 0. |
Write a for loop which writes a countdown from 10 to 0. |
||
=={{header|6502 Assembly}}== |
|||
Code is called as a subroutine (i.e. JSR Start). Printing routines are only partially coded here, specific OS/hardware routines for printing are left unimplemented. |
|||
<lang 6502asm>;An OS/hardware specific routine that is setup to display the Ascii character |
|||
;value contained in the Accumulator |
|||
Send = $9000 ;routine not implemented here |
|||
PrintNewLine = $9050 ;routine not implemented here |
|||
*= $8000 ;set base address |
|||
Start PHA ;push Accumulator and Y register onto stack |
|||
TYA |
|||
PHA |
|||
LDY #10 ;set Y register to loop start value |
|||
TYA ;place loop value in the Accumulator |
|||
Loop JSR PrintTwoDigits |
|||
JSR PrintNewLine |
|||
DEY ;decrement loop value |
|||
BPL Loop ;continue loop if sign flag is clear |
|||
PLA ;pop Y register and Accumulator off of stack |
|||
TAY |
|||
PLA |
|||
RTS ;exit |
|||
;Print value in Accumulator as two hex digits |
|||
PrintTwoDigits |
|||
PHA |
|||
LSR |
|||
LSR |
|||
LSR |
|||
LSR |
|||
JSR PrintDigit |
|||
PLA |
|||
AND #$0F |
|||
JSR PrintDigit |
|||
RTS |
|||
;Convert value in Accumulator to an Ascii hex digit |
|||
PrintDigit |
|||
ORA #$30 |
|||
JSR Send ;routine not implemented here |
|||
RTS </lang> |
|||
=={{header|Ada}}== |
=={{header|Ada}}== |
||
<lang ada>for I in reverse 0..10 loop |
<lang ada>for I in reverse 0..10 loop |
||
Put_Line(Integer'Image(I)); |
Put_Line(Integer'Image(I)); |
||
end loop;</lang> |
end loop;</lang> |
||
=={{header|ALGOL 68}}== |
=={{header|ALGOL 68}}== |
||
{{works with|ALGOL 68|Standard - no extensions to language used}} |
{{works with|ALGOL 68|Standard - no extensions to language used}} |