How to Print Sequence with single for loop?

Hello hope all of you would be safe and sound.My problem is that dears i want to print following output so how could i make program for this.Single for loop should be used.And output will be that.

1
3
5
7
9
11
9
7
5
3
2
1

Plz any one could give me help how to make above output with single for loop.
Last edited on
Is that '2' in the sequence intentional or typo?
Dear i simply want to print following sequence on screen with single for loop.
1
3
5
7
9
11
9
7
5
3
2
1
But the above sequence MUST have a logical pattern! Its fine till 7, 5, 3, but then this 2 appears. Does not satisfy its place in the sequence. I don't think its supposed to be there in the first place...
Also, a single for loop cannot do this. (By "for" loop, I'm assuming while and do-while as well, as their function is same)... You need two loops, one for ascending order of numbers, and the other for descending...
If you really want it within 1 loop, you could have your loop variable "a" ascending 1,3,5 etc, and a variable within the loop ("b") that matches the loop variable "a" until 11. Using an "if" statement the direction of "b" could be switched when "a" reaches 11, and an if-statement could be used for the special case of "2" when descending.
zugvogel, your logic may be correct, if you see her other posts, you'll see that she is a beginner, and using so many loops and counts is not a viable question. I feel that she has simply misunderstood the question, or the question allows use of a while loop as required, but only one for loop.
Topic archived. No new replies allowed.