why does this simple script give such a weird output? The Next CEO of Stack OverflowWhy does...
If Nick Fury and Coulson already knew about aliens (Kree and Skrull) why did they wait until Thor's appearance to start making weapons?
If the heap is zero-initialized for security, then why is the stack merely uninitialized?
Example of a Mathematician/Physicist whose Other Publications during their PhD eclipsed their PhD Thesis
When you upcast Blindness/Deafness, do all targets suffer the same effect?
Legal workarounds for testamentary trust perceived as unfair
How to avoid supervisors with prejudiced views?
Recycling old answers
Rotate a column
Why, when going from special to general relativity, do we just replace partial derivatives with covariant derivatives?
Is wanting to ask what to write an indication that you need to change your story?
Why is the US ranked as #45 in Press Freedom ratings, despite its extremely permissive free speech laws?
The past simple of "gaslight" – "gaslighted" or "gaslit"?
Dominated convergence theorem - what sequence?
Grabbing quick drinks
What did we know about the Kessel run before the prequels?
Is the D&D universe the same as the Forgotten Realms universe?
Why specifically branches as firewood on the Altar?
The exact meaning of 'Mom made me a sandwich'
Unclear about dynamic binding
Why don't programming languages automatically manage the synchronous/asynchronous problem?
How to check if all elements of 1 list are in the *same quantity* and in any order, in the list2?
Prepend last line of stdin to entire stdin
Should I tutor a student who I know has cheated on their homework?
Why the difference in type-inference over the as-pattern in two similar function definitions?
why does this simple script give such a weird output?
The Next CEO of Stack OverflowWhy does rc.local not run this script?Why does this script work in the current directory but fail when placed in the path?Why does this bash script not work?Simple bash script does not want to start at rebootWhy doesn't this bash script execute on Ubuntu, but does on an online environment?Weird output by declare and arrayWhy I obtain this error when I try to perform this simple bash script?Trouble with simple script :(Why is this Bash script not working?Need help with this shell script getting output as zero
I've just started learning how to use arrays so sorry if the answer is somehow obvious. I made a simple program which i thought would just count normally. The output of this program ended up being not only backwards at first but very strange. the program is:
#!/bin/bash
num=1
declare -A A1
while true
do
A1[$(($num + 1))]=$num
num=$(( $num + 1 ))
e=0
for e in ${A1[@]}
do
echo $e
done
echo "e is $e"
echo "num is $num"
sleep 0.1
done
but it's output was started doing some really weird stuff after 8 as shown here:
1
e is 1
num is 2
2
1
e is 1
num is 3
3
2
1
e is 1
num is 4
4
3
2
1
e is 1
num is 5
5
4
3
2
1
e is 1
num is 6
6
5
4
3
2
1
e is 1
num is 7
7
6
5
4
3
2
1
e is 1
num is 8
8
7
6
5
4
3
2
1
e is 1
num is 9
8
7
6
5
4
3
2
1
9
e is 9
num is 10
8
7
6
5
4
3
2
1
9
10
e is 10
num is 11
8
7
6
5
4
3
2
1
11
9
10
e is 10
num is 12
8
7
6
5
4
3
2
1
11
12
9
10
e is 10
num is 13
8
7
6
5
4
3
2
1
11
12
9
10
13
e is 13
num is 14
8
7
6
5
4
3
2
1
11
12
9
10
13
14
e is 14
num is 15
8
7
6
5
4
3
2
1
11
12
9
10
15
13
14
e is 14
num is 16
8
7
6
5
4
3
2
1
11
12
9
10
15
16
13
14
e is 14
num is 17
8
7
6
5
4
3
2
1
17
11
12
9
10
15
16
13
14
e is 14
num is 18
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
e is 14
num is 19
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
19
e is 19
num is 20
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
20
19
e is 19
num is 21
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
21
20
19
e is 19
num is 22
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
22
21
20
19
e is 19
num is 23
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
23
22
21
20
19
e is 19
num is 24
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
24
23
22
21
20
19
e is 19
num is 25
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
25
24
23
22
21
20
19
e is 19
num is 26
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
26
25
24
23
22
21
20
19
e is 19
num is 27
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
26
25
24
23
22
21
20
19
27
e is 27
num is 28
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
26
25
24
23
22
21
20
19
28
27
e is 27
num is 29
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
26
25
24
23
22
21
20
19
28
27
29
e is 29
num is 30
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
26
25
24
23
22
21
20
19
28
27
29
30
e is 30
num is 31
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
26
25
24
23
22
21
20
19
28
27
29
30
31
e is 31
num is 32
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
26
25
24
23
22
21
20
19
28
27
29
30
31
32
e is 32
num is 33
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
26
25
24
23
22
21
20
19
28
27
33
29
30
31
32
e is 32
num is 34
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
26
25
24
23
22
21
20
19
28
27
33
34
29
30
31
32
e is 32
num is 35
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
26
25
24
23
22
21
20
19
28
27
33
34
35
29
30
31
32
e is 32
num is 36
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
26
25
24
23
22
21
20
19
28
27
33
34
35
36
29
30
31
32
e is 32
num is 37
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
26
25
24
23
22
21
20
19
28
27
33
34
35
36
29
30
31
32
37
e is 37
num is 38
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
26
25
24
23
22
21
20
19
28
27
33
34
35
36
29
30
31
32
37
38
e is 38
num is 39
39
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
26
25
24
23
22
21
20
19
28
27
33
34
35
36
29
30
31
32
37
38
e is 38
num is 40
^C
can anybody explain this?
command-line bash scripts
add a comment |
I've just started learning how to use arrays so sorry if the answer is somehow obvious. I made a simple program which i thought would just count normally. The output of this program ended up being not only backwards at first but very strange. the program is:
#!/bin/bash
num=1
declare -A A1
while true
do
A1[$(($num + 1))]=$num
num=$(( $num + 1 ))
e=0
for e in ${A1[@]}
do
echo $e
done
echo "e is $e"
echo "num is $num"
sleep 0.1
done
but it's output was started doing some really weird stuff after 8 as shown here:
1
e is 1
num is 2
2
1
e is 1
num is 3
3
2
1
e is 1
num is 4
4
3
2
1
e is 1
num is 5
5
4
3
2
1
e is 1
num is 6
6
5
4
3
2
1
e is 1
num is 7
7
6
5
4
3
2
1
e is 1
num is 8
8
7
6
5
4
3
2
1
e is 1
num is 9
8
7
6
5
4
3
2
1
9
e is 9
num is 10
8
7
6
5
4
3
2
1
9
10
e is 10
num is 11
8
7
6
5
4
3
2
1
11
9
10
e is 10
num is 12
8
7
6
5
4
3
2
1
11
12
9
10
e is 10
num is 13
8
7
6
5
4
3
2
1
11
12
9
10
13
e is 13
num is 14
8
7
6
5
4
3
2
1
11
12
9
10
13
14
e is 14
num is 15
8
7
6
5
4
3
2
1
11
12
9
10
15
13
14
e is 14
num is 16
8
7
6
5
4
3
2
1
11
12
9
10
15
16
13
14
e is 14
num is 17
8
7
6
5
4
3
2
1
17
11
12
9
10
15
16
13
14
e is 14
num is 18
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
e is 14
num is 19
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
19
e is 19
num is 20
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
20
19
e is 19
num is 21
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
21
20
19
e is 19
num is 22
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
22
21
20
19
e is 19
num is 23
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
23
22
21
20
19
e is 19
num is 24
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
24
23
22
21
20
19
e is 19
num is 25
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
25
24
23
22
21
20
19
e is 19
num is 26
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
26
25
24
23
22
21
20
19
e is 19
num is 27
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
26
25
24
23
22
21
20
19
27
e is 27
num is 28
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
26
25
24
23
22
21
20
19
28
27
e is 27
num is 29
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
26
25
24
23
22
21
20
19
28
27
29
e is 29
num is 30
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
26
25
24
23
22
21
20
19
28
27
29
30
e is 30
num is 31
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
26
25
24
23
22
21
20
19
28
27
29
30
31
e is 31
num is 32
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
26
25
24
23
22
21
20
19
28
27
29
30
31
32
e is 32
num is 33
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
26
25
24
23
22
21
20
19
28
27
33
29
30
31
32
e is 32
num is 34
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
26
25
24
23
22
21
20
19
28
27
33
34
29
30
31
32
e is 32
num is 35
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
26
25
24
23
22
21
20
19
28
27
33
34
35
29
30
31
32
e is 32
num is 36
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
26
25
24
23
22
21
20
19
28
27
33
34
35
36
29
30
31
32
e is 32
num is 37
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
26
25
24
23
22
21
20
19
28
27
33
34
35
36
29
30
31
32
37
e is 37
num is 38
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
26
25
24
23
22
21
20
19
28
27
33
34
35
36
29
30
31
32
37
38
e is 38
num is 39
39
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
26
25
24
23
22
21
20
19
28
27
33
34
35
36
29
30
31
32
37
38
e is 38
num is 40
^C
can anybody explain this?
command-line bash scripts
You're iterating on associative array keys. Associative arrays aren't necessarily sorted.
– Sergiy Kolodyazhnyy
12 mins ago
add a comment |
I've just started learning how to use arrays so sorry if the answer is somehow obvious. I made a simple program which i thought would just count normally. The output of this program ended up being not only backwards at first but very strange. the program is:
#!/bin/bash
num=1
declare -A A1
while true
do
A1[$(($num + 1))]=$num
num=$(( $num + 1 ))
e=0
for e in ${A1[@]}
do
echo $e
done
echo "e is $e"
echo "num is $num"
sleep 0.1
done
but it's output was started doing some really weird stuff after 8 as shown here:
1
e is 1
num is 2
2
1
e is 1
num is 3
3
2
1
e is 1
num is 4
4
3
2
1
e is 1
num is 5
5
4
3
2
1
e is 1
num is 6
6
5
4
3
2
1
e is 1
num is 7
7
6
5
4
3
2
1
e is 1
num is 8
8
7
6
5
4
3
2
1
e is 1
num is 9
8
7
6
5
4
3
2
1
9
e is 9
num is 10
8
7
6
5
4
3
2
1
9
10
e is 10
num is 11
8
7
6
5
4
3
2
1
11
9
10
e is 10
num is 12
8
7
6
5
4
3
2
1
11
12
9
10
e is 10
num is 13
8
7
6
5
4
3
2
1
11
12
9
10
13
e is 13
num is 14
8
7
6
5
4
3
2
1
11
12
9
10
13
14
e is 14
num is 15
8
7
6
5
4
3
2
1
11
12
9
10
15
13
14
e is 14
num is 16
8
7
6
5
4
3
2
1
11
12
9
10
15
16
13
14
e is 14
num is 17
8
7
6
5
4
3
2
1
17
11
12
9
10
15
16
13
14
e is 14
num is 18
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
e is 14
num is 19
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
19
e is 19
num is 20
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
20
19
e is 19
num is 21
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
21
20
19
e is 19
num is 22
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
22
21
20
19
e is 19
num is 23
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
23
22
21
20
19
e is 19
num is 24
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
24
23
22
21
20
19
e is 19
num is 25
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
25
24
23
22
21
20
19
e is 19
num is 26
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
26
25
24
23
22
21
20
19
e is 19
num is 27
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
26
25
24
23
22
21
20
19
27
e is 27
num is 28
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
26
25
24
23
22
21
20
19
28
27
e is 27
num is 29
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
26
25
24
23
22
21
20
19
28
27
29
e is 29
num is 30
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
26
25
24
23
22
21
20
19
28
27
29
30
e is 30
num is 31
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
26
25
24
23
22
21
20
19
28
27
29
30
31
e is 31
num is 32
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
26
25
24
23
22
21
20
19
28
27
29
30
31
32
e is 32
num is 33
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
26
25
24
23
22
21
20
19
28
27
33
29
30
31
32
e is 32
num is 34
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
26
25
24
23
22
21
20
19
28
27
33
34
29
30
31
32
e is 32
num is 35
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
26
25
24
23
22
21
20
19
28
27
33
34
35
29
30
31
32
e is 32
num is 36
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
26
25
24
23
22
21
20
19
28
27
33
34
35
36
29
30
31
32
e is 32
num is 37
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
26
25
24
23
22
21
20
19
28
27
33
34
35
36
29
30
31
32
37
e is 37
num is 38
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
26
25
24
23
22
21
20
19
28
27
33
34
35
36
29
30
31
32
37
38
e is 38
num is 39
39
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
26
25
24
23
22
21
20
19
28
27
33
34
35
36
29
30
31
32
37
38
e is 38
num is 40
^C
can anybody explain this?
command-line bash scripts
I've just started learning how to use arrays so sorry if the answer is somehow obvious. I made a simple program which i thought would just count normally. The output of this program ended up being not only backwards at first but very strange. the program is:
#!/bin/bash
num=1
declare -A A1
while true
do
A1[$(($num + 1))]=$num
num=$(( $num + 1 ))
e=0
for e in ${A1[@]}
do
echo $e
done
echo "e is $e"
echo "num is $num"
sleep 0.1
done
but it's output was started doing some really weird stuff after 8 as shown here:
1
e is 1
num is 2
2
1
e is 1
num is 3
3
2
1
e is 1
num is 4
4
3
2
1
e is 1
num is 5
5
4
3
2
1
e is 1
num is 6
6
5
4
3
2
1
e is 1
num is 7
7
6
5
4
3
2
1
e is 1
num is 8
8
7
6
5
4
3
2
1
e is 1
num is 9
8
7
6
5
4
3
2
1
9
e is 9
num is 10
8
7
6
5
4
3
2
1
9
10
e is 10
num is 11
8
7
6
5
4
3
2
1
11
9
10
e is 10
num is 12
8
7
6
5
4
3
2
1
11
12
9
10
e is 10
num is 13
8
7
6
5
4
3
2
1
11
12
9
10
13
e is 13
num is 14
8
7
6
5
4
3
2
1
11
12
9
10
13
14
e is 14
num is 15
8
7
6
5
4
3
2
1
11
12
9
10
15
13
14
e is 14
num is 16
8
7
6
5
4
3
2
1
11
12
9
10
15
16
13
14
e is 14
num is 17
8
7
6
5
4
3
2
1
17
11
12
9
10
15
16
13
14
e is 14
num is 18
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
e is 14
num is 19
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
19
e is 19
num is 20
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
20
19
e is 19
num is 21
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
21
20
19
e is 19
num is 22
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
22
21
20
19
e is 19
num is 23
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
23
22
21
20
19
e is 19
num is 24
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
24
23
22
21
20
19
e is 19
num is 25
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
25
24
23
22
21
20
19
e is 19
num is 26
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
26
25
24
23
22
21
20
19
e is 19
num is 27
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
26
25
24
23
22
21
20
19
27
e is 27
num is 28
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
26
25
24
23
22
21
20
19
28
27
e is 27
num is 29
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
26
25
24
23
22
21
20
19
28
27
29
e is 29
num is 30
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
26
25
24
23
22
21
20
19
28
27
29
30
e is 30
num is 31
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
26
25
24
23
22
21
20
19
28
27
29
30
31
e is 31
num is 32
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
26
25
24
23
22
21
20
19
28
27
29
30
31
32
e is 32
num is 33
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
26
25
24
23
22
21
20
19
28
27
33
29
30
31
32
e is 32
num is 34
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
26
25
24
23
22
21
20
19
28
27
33
34
29
30
31
32
e is 32
num is 35
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
26
25
24
23
22
21
20
19
28
27
33
34
35
29
30
31
32
e is 32
num is 36
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
26
25
24
23
22
21
20
19
28
27
33
34
35
36
29
30
31
32
e is 32
num is 37
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
26
25
24
23
22
21
20
19
28
27
33
34
35
36
29
30
31
32
37
e is 37
num is 38
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
26
25
24
23
22
21
20
19
28
27
33
34
35
36
29
30
31
32
37
38
e is 38
num is 39
39
8
7
6
5
4
3
2
1
17
18
11
12
9
10
15
16
13
14
26
25
24
23
22
21
20
19
28
27
33
34
35
36
29
30
31
32
37
38
e is 38
num is 40
^C
can anybody explain this?
command-line bash scripts
command-line bash scripts
edited 17 mins ago
TheRedStormer
asked 30 mins ago
TheRedStormerTheRedStormer
63
63
You're iterating on associative array keys. Associative arrays aren't necessarily sorted.
– Sergiy Kolodyazhnyy
12 mins ago
add a comment |
You're iterating on associative array keys. Associative arrays aren't necessarily sorted.
– Sergiy Kolodyazhnyy
12 mins ago
You're iterating on associative array keys. Associative arrays aren't necessarily sorted.
– Sergiy Kolodyazhnyy
12 mins ago
You're iterating on associative array keys. Associative arrays aren't necessarily sorted.
– Sergiy Kolodyazhnyy
12 mins ago
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1130065%2fwhy-does-this-simple-script-give-such-a-weird-output%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Ask Ubuntu!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1130065%2fwhy-does-this-simple-script-give-such-a-weird-output%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
You're iterating on associative array keys. Associative arrays aren't necessarily sorted.
– Sergiy Kolodyazhnyy
12 mins ago