for loop to iterate through some file nth position
How do I iterate for nth file in a for loop in unix?
below some code I have tried but not succeeded
#!/bin/bash
#
n=2
array=( "CTL_MLPOSDTLP1_1.ctl" "CTL_MLPOSDTLP1_2.ctl" "CTL_MLPOSDTLP1_3.ctl" )
for x in "${array[@]}"
for ((x=${array[@]}; x<=n; x++));
do
echo "array[x]"
done
shell for
add a comment |
How do I iterate for nth file in a for loop in unix?
below some code I have tried but not succeeded
#!/bin/bash
#
n=2
array=( "CTL_MLPOSDTLP1_1.ctl" "CTL_MLPOSDTLP1_2.ctl" "CTL_MLPOSDTLP1_3.ctl" )
for x in "${array[@]}"
for ((x=${array[@]}; x<=n; x++));
do
echo "array[x]"
done
shell for
What do you mean by "some file nth position"? What is the expected/desired output?
– G-Man
yesterday
@roaima: I respect John1024, and I believe that he has written many answers much better than this one. It is an adequate answer to the questions “How do I iterate through the elements of an array?” and “How do I access elements of an array by their index numbers?” — questions that have probably been asked at least a handful of times, and have probably received answers that are clearer and more coherent, elsewhere. … (Cont’d)
– G-Man
yesterday
(Cont’d) … I’m concerned that (1) anybody who wants to know how to iterate through the elements of an array won’t find this question, or won’t recognize it as being equivalent to their question, because of how poorly this one is worded, and (2) anybody who wants to know what this question appears to be asking (how do I look at every other (i.e., every 2nd) element of an array?) won’t be satisfied by John’s answer.
– G-Man
yesterday
@roaima: But my point is that it’s a duplicate answer. If the question is incomprehensible, how are we to choose one that means the same thing?
– G-Man
yesterday
@G-Man I've no strong feelings either way. I'll pull out.
– roaima
15 hours ago
add a comment |
How do I iterate for nth file in a for loop in unix?
below some code I have tried but not succeeded
#!/bin/bash
#
n=2
array=( "CTL_MLPOSDTLP1_1.ctl" "CTL_MLPOSDTLP1_2.ctl" "CTL_MLPOSDTLP1_3.ctl" )
for x in "${array[@]}"
for ((x=${array[@]}; x<=n; x++));
do
echo "array[x]"
done
shell for
How do I iterate for nth file in a for loop in unix?
below some code I have tried but not succeeded
#!/bin/bash
#
n=2
array=( "CTL_MLPOSDTLP1_1.ctl" "CTL_MLPOSDTLP1_2.ctl" "CTL_MLPOSDTLP1_3.ctl" )
for x in "${array[@]}"
for ((x=${array[@]}; x<=n; x++));
do
echo "array[x]"
done
shell for
shell for
edited Nov 11 '14 at 23:19
Gilles
529k12810601586
529k12810601586
asked Nov 11 '14 at 6:23
sabyasachi kar
184
184
What do you mean by "some file nth position"? What is the expected/desired output?
– G-Man
yesterday
@roaima: I respect John1024, and I believe that he has written many answers much better than this one. It is an adequate answer to the questions “How do I iterate through the elements of an array?” and “How do I access elements of an array by their index numbers?” — questions that have probably been asked at least a handful of times, and have probably received answers that are clearer and more coherent, elsewhere. … (Cont’d)
– G-Man
yesterday
(Cont’d) … I’m concerned that (1) anybody who wants to know how to iterate through the elements of an array won’t find this question, or won’t recognize it as being equivalent to their question, because of how poorly this one is worded, and (2) anybody who wants to know what this question appears to be asking (how do I look at every other (i.e., every 2nd) element of an array?) won’t be satisfied by John’s answer.
– G-Man
yesterday
@roaima: But my point is that it’s a duplicate answer. If the question is incomprehensible, how are we to choose one that means the same thing?
– G-Man
yesterday
@G-Man I've no strong feelings either way. I'll pull out.
– roaima
15 hours ago
add a comment |
What do you mean by "some file nth position"? What is the expected/desired output?
– G-Man
yesterday
@roaima: I respect John1024, and I believe that he has written many answers much better than this one. It is an adequate answer to the questions “How do I iterate through the elements of an array?” and “How do I access elements of an array by their index numbers?” — questions that have probably been asked at least a handful of times, and have probably received answers that are clearer and more coherent, elsewhere. … (Cont’d)
– G-Man
yesterday
(Cont’d) … I’m concerned that (1) anybody who wants to know how to iterate through the elements of an array won’t find this question, or won’t recognize it as being equivalent to their question, because of how poorly this one is worded, and (2) anybody who wants to know what this question appears to be asking (how do I look at every other (i.e., every 2nd) element of an array?) won’t be satisfied by John’s answer.
– G-Man
yesterday
@roaima: But my point is that it’s a duplicate answer. If the question is incomprehensible, how are we to choose one that means the same thing?
– G-Man
yesterday
@G-Man I've no strong feelings either way. I'll pull out.
– roaima
15 hours ago
What do you mean by "some file nth position"? What is the expected/desired output?
– G-Man
yesterday
What do you mean by "some file nth position"? What is the expected/desired output?
– G-Man
yesterday
@roaima: I respect John1024, and I believe that he has written many answers much better than this one. It is an adequate answer to the questions “How do I iterate through the elements of an array?” and “How do I access elements of an array by their index numbers?” — questions that have probably been asked at least a handful of times, and have probably received answers that are clearer and more coherent, elsewhere. … (Cont’d)
– G-Man
yesterday
@roaima: I respect John1024, and I believe that he has written many answers much better than this one. It is an adequate answer to the questions “How do I iterate through the elements of an array?” and “How do I access elements of an array by their index numbers?” — questions that have probably been asked at least a handful of times, and have probably received answers that are clearer and more coherent, elsewhere. … (Cont’d)
– G-Man
yesterday
(Cont’d) … I’m concerned that (1) anybody who wants to know how to iterate through the elements of an array won’t find this question, or won’t recognize it as being equivalent to their question, because of how poorly this one is worded, and (2) anybody who wants to know what this question appears to be asking (how do I look at every other (i.e., every 2nd) element of an array?) won’t be satisfied by John’s answer.
– G-Man
yesterday
(Cont’d) … I’m concerned that (1) anybody who wants to know how to iterate through the elements of an array won’t find this question, or won’t recognize it as being equivalent to their question, because of how poorly this one is worded, and (2) anybody who wants to know what this question appears to be asking (how do I look at every other (i.e., every 2nd) element of an array?) won’t be satisfied by John’s answer.
– G-Man
yesterday
@roaima: But my point is that it’s a duplicate answer. If the question is incomprehensible, how are we to choose one that means the same thing?
– G-Man
yesterday
@roaima: But my point is that it’s a duplicate answer. If the question is incomprehensible, how are we to choose one that means the same thing?
– G-Man
yesterday
@G-Man I've no strong feelings either way. I'll pull out.
– roaima
15 hours ago
@G-Man I've no strong feelings either way. I'll pull out.
– roaima
15 hours ago
add a comment |
2 Answers
2
active
oldest
votes
Here are two ways to loop over an array:
#!/bin/bash
array=( "CTL_MLPOSDTLP1_1.ctl" "CTL_MLPOSDTLP1_2.ctl" "CTL_MLPOSDTLP1_3.ctl" )
echo Loop 1
for x in "${array[@]}"
do
echo "$x"
done
echo Loop 2
for ((x=0; x<${#array[@]}; x++));
do
echo "${array[x]}"
done
Looping over selected items
This scripts allows you to specify on the command line which elements from the array ate to be processed:
#!/bin/bash
array=( "CTL_MLPOSDTLP1_1.ctl" "CTL_MLPOSDTLP1_2.ctl" "CTL_MLPOSDTLP1_3.ctl" )
for x in "$@"
do
echo "${array[x]}"
done
Suppose we want to loop over the first two and skip the third. (Since bash uses zero-based indexing, the first two are number 0 and number 1.) Use:
$ bash script.sh 0 1
CTL_MLPOSDTLP1_1.ctl
CTL_MLPOSDTLP1_2.ctl
To run just the third:
$ bash s.sh 2
CTL_MLPOSDTLP1_3.ctl
To iterate from 0 to n-1
for ((x=0; x<n; x++));
do
echo "${array[x]}"
done
but how abt if i want to iterate only 2 time ? means only for 2 files from the array i want to do some operation and skip the 3rd file as i dont want it for this time .. may next time i want to iterate all files in the array list?
– sabyasachi kar
Nov 11 '14 at 6:37
@sabyasachikar OK. I added a script which lets you select from the command line which array elements to process. See updated answer.
– John1024
Nov 11 '14 at 6:49
Thanks @John, nice information on zero based indexing :) ... but i want it inside the shell,not from the command line as i need to take the nth value from a config file. Regards sabya
– sabyasachi kar
Nov 11 '14 at 6:54
What is your config file format? Is there any other information that I need that you haven't told me yet?
– John1024
Nov 11 '14 at 6:57
1
+1. Good answers in this time window do not get enough love
– iruvar
Nov 11 '14 at 7:34
|
show 6 more comments
#!bin/bash
n=2
array=( "CTL_MLPOSDTLP1_1.ctl" "CTL_MLPOSDTLP1_2.ctl" "CTL_MLPOSDTLP1_3.ctl" )
for ((x=0; x<=n-1; x++));
do
echo "${array[x]}"
done
Thanks @john for the help as I edited and got the correct output; it's working now :)
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
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: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
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%2funix.stackexchange.com%2fquestions%2f167269%2ffor-loop-to-iterate-through-some-file-nth-position%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Here are two ways to loop over an array:
#!/bin/bash
array=( "CTL_MLPOSDTLP1_1.ctl" "CTL_MLPOSDTLP1_2.ctl" "CTL_MLPOSDTLP1_3.ctl" )
echo Loop 1
for x in "${array[@]}"
do
echo "$x"
done
echo Loop 2
for ((x=0; x<${#array[@]}; x++));
do
echo "${array[x]}"
done
Looping over selected items
This scripts allows you to specify on the command line which elements from the array ate to be processed:
#!/bin/bash
array=( "CTL_MLPOSDTLP1_1.ctl" "CTL_MLPOSDTLP1_2.ctl" "CTL_MLPOSDTLP1_3.ctl" )
for x in "$@"
do
echo "${array[x]}"
done
Suppose we want to loop over the first two and skip the third. (Since bash uses zero-based indexing, the first two are number 0 and number 1.) Use:
$ bash script.sh 0 1
CTL_MLPOSDTLP1_1.ctl
CTL_MLPOSDTLP1_2.ctl
To run just the third:
$ bash s.sh 2
CTL_MLPOSDTLP1_3.ctl
To iterate from 0 to n-1
for ((x=0; x<n; x++));
do
echo "${array[x]}"
done
but how abt if i want to iterate only 2 time ? means only for 2 files from the array i want to do some operation and skip the 3rd file as i dont want it for this time .. may next time i want to iterate all files in the array list?
– sabyasachi kar
Nov 11 '14 at 6:37
@sabyasachikar OK. I added a script which lets you select from the command line which array elements to process. See updated answer.
– John1024
Nov 11 '14 at 6:49
Thanks @John, nice information on zero based indexing :) ... but i want it inside the shell,not from the command line as i need to take the nth value from a config file. Regards sabya
– sabyasachi kar
Nov 11 '14 at 6:54
What is your config file format? Is there any other information that I need that you haven't told me yet?
– John1024
Nov 11 '14 at 6:57
1
+1. Good answers in this time window do not get enough love
– iruvar
Nov 11 '14 at 7:34
|
show 6 more comments
Here are two ways to loop over an array:
#!/bin/bash
array=( "CTL_MLPOSDTLP1_1.ctl" "CTL_MLPOSDTLP1_2.ctl" "CTL_MLPOSDTLP1_3.ctl" )
echo Loop 1
for x in "${array[@]}"
do
echo "$x"
done
echo Loop 2
for ((x=0; x<${#array[@]}; x++));
do
echo "${array[x]}"
done
Looping over selected items
This scripts allows you to specify on the command line which elements from the array ate to be processed:
#!/bin/bash
array=( "CTL_MLPOSDTLP1_1.ctl" "CTL_MLPOSDTLP1_2.ctl" "CTL_MLPOSDTLP1_3.ctl" )
for x in "$@"
do
echo "${array[x]}"
done
Suppose we want to loop over the first two and skip the third. (Since bash uses zero-based indexing, the first two are number 0 and number 1.) Use:
$ bash script.sh 0 1
CTL_MLPOSDTLP1_1.ctl
CTL_MLPOSDTLP1_2.ctl
To run just the third:
$ bash s.sh 2
CTL_MLPOSDTLP1_3.ctl
To iterate from 0 to n-1
for ((x=0; x<n; x++));
do
echo "${array[x]}"
done
but how abt if i want to iterate only 2 time ? means only for 2 files from the array i want to do some operation and skip the 3rd file as i dont want it for this time .. may next time i want to iterate all files in the array list?
– sabyasachi kar
Nov 11 '14 at 6:37
@sabyasachikar OK. I added a script which lets you select from the command line which array elements to process. See updated answer.
– John1024
Nov 11 '14 at 6:49
Thanks @John, nice information on zero based indexing :) ... but i want it inside the shell,not from the command line as i need to take the nth value from a config file. Regards sabya
– sabyasachi kar
Nov 11 '14 at 6:54
What is your config file format? Is there any other information that I need that you haven't told me yet?
– John1024
Nov 11 '14 at 6:57
1
+1. Good answers in this time window do not get enough love
– iruvar
Nov 11 '14 at 7:34
|
show 6 more comments
Here are two ways to loop over an array:
#!/bin/bash
array=( "CTL_MLPOSDTLP1_1.ctl" "CTL_MLPOSDTLP1_2.ctl" "CTL_MLPOSDTLP1_3.ctl" )
echo Loop 1
for x in "${array[@]}"
do
echo "$x"
done
echo Loop 2
for ((x=0; x<${#array[@]}; x++));
do
echo "${array[x]}"
done
Looping over selected items
This scripts allows you to specify on the command line which elements from the array ate to be processed:
#!/bin/bash
array=( "CTL_MLPOSDTLP1_1.ctl" "CTL_MLPOSDTLP1_2.ctl" "CTL_MLPOSDTLP1_3.ctl" )
for x in "$@"
do
echo "${array[x]}"
done
Suppose we want to loop over the first two and skip the third. (Since bash uses zero-based indexing, the first two are number 0 and number 1.) Use:
$ bash script.sh 0 1
CTL_MLPOSDTLP1_1.ctl
CTL_MLPOSDTLP1_2.ctl
To run just the third:
$ bash s.sh 2
CTL_MLPOSDTLP1_3.ctl
To iterate from 0 to n-1
for ((x=0; x<n; x++));
do
echo "${array[x]}"
done
Here are two ways to loop over an array:
#!/bin/bash
array=( "CTL_MLPOSDTLP1_1.ctl" "CTL_MLPOSDTLP1_2.ctl" "CTL_MLPOSDTLP1_3.ctl" )
echo Loop 1
for x in "${array[@]}"
do
echo "$x"
done
echo Loop 2
for ((x=0; x<${#array[@]}; x++));
do
echo "${array[x]}"
done
Looping over selected items
This scripts allows you to specify on the command line which elements from the array ate to be processed:
#!/bin/bash
array=( "CTL_MLPOSDTLP1_1.ctl" "CTL_MLPOSDTLP1_2.ctl" "CTL_MLPOSDTLP1_3.ctl" )
for x in "$@"
do
echo "${array[x]}"
done
Suppose we want to loop over the first two and skip the third. (Since bash uses zero-based indexing, the first two are number 0 and number 1.) Use:
$ bash script.sh 0 1
CTL_MLPOSDTLP1_1.ctl
CTL_MLPOSDTLP1_2.ctl
To run just the third:
$ bash s.sh 2
CTL_MLPOSDTLP1_3.ctl
To iterate from 0 to n-1
for ((x=0; x<n; x++));
do
echo "${array[x]}"
done
edited Nov 11 '14 at 7:21
answered Nov 11 '14 at 6:29
John1024
45.9k4104119
45.9k4104119
but how abt if i want to iterate only 2 time ? means only for 2 files from the array i want to do some operation and skip the 3rd file as i dont want it for this time .. may next time i want to iterate all files in the array list?
– sabyasachi kar
Nov 11 '14 at 6:37
@sabyasachikar OK. I added a script which lets you select from the command line which array elements to process. See updated answer.
– John1024
Nov 11 '14 at 6:49
Thanks @John, nice information on zero based indexing :) ... but i want it inside the shell,not from the command line as i need to take the nth value from a config file. Regards sabya
– sabyasachi kar
Nov 11 '14 at 6:54
What is your config file format? Is there any other information that I need that you haven't told me yet?
– John1024
Nov 11 '14 at 6:57
1
+1. Good answers in this time window do not get enough love
– iruvar
Nov 11 '14 at 7:34
|
show 6 more comments
but how abt if i want to iterate only 2 time ? means only for 2 files from the array i want to do some operation and skip the 3rd file as i dont want it for this time .. may next time i want to iterate all files in the array list?
– sabyasachi kar
Nov 11 '14 at 6:37
@sabyasachikar OK. I added a script which lets you select from the command line which array elements to process. See updated answer.
– John1024
Nov 11 '14 at 6:49
Thanks @John, nice information on zero based indexing :) ... but i want it inside the shell,not from the command line as i need to take the nth value from a config file. Regards sabya
– sabyasachi kar
Nov 11 '14 at 6:54
What is your config file format? Is there any other information that I need that you haven't told me yet?
– John1024
Nov 11 '14 at 6:57
1
+1. Good answers in this time window do not get enough love
– iruvar
Nov 11 '14 at 7:34
but how abt if i want to iterate only 2 time ? means only for 2 files from the array i want to do some operation and skip the 3rd file as i dont want it for this time .. may next time i want to iterate all files in the array list?
– sabyasachi kar
Nov 11 '14 at 6:37
but how abt if i want to iterate only 2 time ? means only for 2 files from the array i want to do some operation and skip the 3rd file as i dont want it for this time .. may next time i want to iterate all files in the array list?
– sabyasachi kar
Nov 11 '14 at 6:37
@sabyasachikar OK. I added a script which lets you select from the command line which array elements to process. See updated answer.
– John1024
Nov 11 '14 at 6:49
@sabyasachikar OK. I added a script which lets you select from the command line which array elements to process. See updated answer.
– John1024
Nov 11 '14 at 6:49
Thanks @John, nice information on zero based indexing :) ... but i want it inside the shell,not from the command line as i need to take the nth value from a config file. Regards sabya
– sabyasachi kar
Nov 11 '14 at 6:54
Thanks @John, nice information on zero based indexing :) ... but i want it inside the shell,not from the command line as i need to take the nth value from a config file. Regards sabya
– sabyasachi kar
Nov 11 '14 at 6:54
What is your config file format? Is there any other information that I need that you haven't told me yet?
– John1024
Nov 11 '14 at 6:57
What is your config file format? Is there any other information that I need that you haven't told me yet?
– John1024
Nov 11 '14 at 6:57
1
1
+1. Good answers in this time window do not get enough love
– iruvar
Nov 11 '14 at 7:34
+1. Good answers in this time window do not get enough love
– iruvar
Nov 11 '14 at 7:34
|
show 6 more comments
#!bin/bash
n=2
array=( "CTL_MLPOSDTLP1_1.ctl" "CTL_MLPOSDTLP1_2.ctl" "CTL_MLPOSDTLP1_3.ctl" )
for ((x=0; x<=n-1; x++));
do
echo "${array[x]}"
done
Thanks @john for the help as I edited and got the correct output; it's working now :)
add a comment |
#!bin/bash
n=2
array=( "CTL_MLPOSDTLP1_1.ctl" "CTL_MLPOSDTLP1_2.ctl" "CTL_MLPOSDTLP1_3.ctl" )
for ((x=0; x<=n-1; x++));
do
echo "${array[x]}"
done
Thanks @john for the help as I edited and got the correct output; it's working now :)
add a comment |
#!bin/bash
n=2
array=( "CTL_MLPOSDTLP1_1.ctl" "CTL_MLPOSDTLP1_2.ctl" "CTL_MLPOSDTLP1_3.ctl" )
for ((x=0; x<=n-1; x++));
do
echo "${array[x]}"
done
Thanks @john for the help as I edited and got the correct output; it's working now :)
#!bin/bash
n=2
array=( "CTL_MLPOSDTLP1_1.ctl" "CTL_MLPOSDTLP1_2.ctl" "CTL_MLPOSDTLP1_3.ctl" )
for ((x=0; x<=n-1; x++));
do
echo "${array[x]}"
done
Thanks @john for the help as I edited and got the correct output; it's working now :)
edited yesterday
Jeff Schaller
39k1053125
39k1053125
answered Nov 11 '14 at 7:23
sabyasachi kar
184
184
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- 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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2funix.stackexchange.com%2fquestions%2f167269%2ffor-loop-to-iterate-through-some-file-nth-position%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
What do you mean by "some file nth position"? What is the expected/desired output?
– G-Man
yesterday
@roaima: I respect John1024, and I believe that he has written many answers much better than this one. It is an adequate answer to the questions “How do I iterate through the elements of an array?” and “How do I access elements of an array by their index numbers?” — questions that have probably been asked at least a handful of times, and have probably received answers that are clearer and more coherent, elsewhere. … (Cont’d)
– G-Man
yesterday
(Cont’d) … I’m concerned that (1) anybody who wants to know how to iterate through the elements of an array won’t find this question, or won’t recognize it as being equivalent to their question, because of how poorly this one is worded, and (2) anybody who wants to know what this question appears to be asking (how do I look at every other (i.e., every 2nd) element of an array?) won’t be satisfied by John’s answer.
– G-Man
yesterday
@roaima: But my point is that it’s a duplicate answer. If the question is incomprehensible, how are we to choose one that means the same thing?
– G-Man
yesterday
@G-Man I've no strong feelings either way. I'll pull out.
– roaima
15 hours ago