Pooh program example 03-print-array.p

Test 03-print-array.p

Source of programm

# array test: print all elements of array, iterate with while statement.

arr = [  1, 2, 3, 5, 7, 11, 13, 17 ]

i = 1
while arr [ i ] != Null
    println( ~msg 'prime number i ' .. arr[ i]  )
    i = i + 1
end

Standard output for 03-print-array.p

prime number i 1
prime number i 2
prime number i 3
prime number i 5
prime number i 7
prime number i 11
prime number i 13
prime number i 17

Trace output for 03-print-array.p

003|arr = [ 1 , 2 , 3 , 5 , 7 , 11 , 13 , 17] 
005|i = 1
006|while (arr[i:1]:1 != Null):true
007| println( ~msg 'prime number i ' .. arr[i:1]:1 )...
008| i = (i:1 + 1):2
009|end
006|while (arr[i:2]:2 != Null):true
007| println( ~msg 'prime number i ' .. arr[i:2]:2 )...
008| i = (i:2 + 1):3
009|end
006|while (arr[i:3]:3 != Null):true
007| println( ~msg 'prime number i ' .. arr[i:3]:3 )...
008| i = (i:3 + 1):4
009|end
006|while (arr[i:4]:5 != Null):true
007| println( ~msg 'prime number i ' .. arr[i:4]:5 )...
008| i = (i:4 + 1):5
009|end
006|while (arr[i:5]:7 != Null):true
007| println( ~msg 'prime number i ' .. arr[i:5]:7 )...
008| i = (i:5 + 1):6
009|end
006|while (arr[i:6]:11 != Null):true
007| println( ~msg 'prime number i ' .. arr[i:6]:11 )...
008| i = (i:6 + 1):7
009|end
006|while (arr[i:7]:13 != Null):true
007| println( ~msg 'prime number i ' .. arr[i:7]:13 )...
008| i = (i:7 + 1):8
009|end
006|while (arr[i:8]:17 != Null):true
007| println( ~msg 'prime number i ' .. arr[i:8]:17 )...
008| i = (i:8 + 1):9
009|end
006|while (arr[i:9]:Null != Null):false
009|end # finish loop