Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Nested For Loop [EXAMPLES!]

Name: ALPHA 2011-07-05 13:38

Hi,
Here is a collection of few examples for NESTED FOR LOOP.
Simple codes in how to use nested loops,
There is only the code, no explanation (not good at explaining anything)
So, just try to understand the program
Hope this will help as much people as possible
Let's Stop talking and just begin

OK
Here we go!

1.Get the following output :
a.
1
12
123
1234
12345
123456
1234567
12345678
123456789

//Numbers Ladder
//Nested Loops
//By ALPHA
//On 22 Oct 2008
//www.CodeCall.net
//----------------------
public class testFor
{
    public static void main(String [] args)
    {
        for (int i=1; i<=9; i++)
        {
            System.out.println();
            for (int j=1; j<=i; j++)
            {
                System.out.print(j);
            }
        }
      System.out.println();
    }
}

Name: Anonymous 2011-07-06 9:55

>>17
No it's not

; assemble with:
;   nasm -f elf64 -o prog.o prog.asm
;
; link with:
;   gcc prog.o
;
; run with:
;   ./a.out

; Purpose: nested for-loop
; author:  anonymous
; licence: false

; TODO: optimize shit, it's slower than C now ;/

extern printf
extern putchar

section .data
    format_string: db "%u", 0h

section .text
global main

main:
    push rbp
    mov rbp, rsp
    xor rdi, rdi
    push r10
    push rbx
    xor r10, r10

    ; initialize loop
    xor bx, bx
    first_loop:
        inc bx
        xor r10w, r10w ;second loop's counter
        second_loop:
            inc r10w
            ; print number
            xor rsi, rsi
            mov si, r10w
            mov rdi, format_string
            call printf
            cmp r10w, bx ; second loop end
            jl second_loop
        mov edi, 0ah
        call putchar
        cmp bx, 9h ; first loop end
        jl first_loop

    pop rbx
    pop r10
    ; return success
    leave
    xor rax, rax
    ret


simple as hell

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List