answersLogoWhite

0

It may not be worthwhile to write a loop at all in such a simple case. On the other hand, you can make two loops, one for the ascending part, and one for the descending part. Finally, you can use a single loop, and a condition inside it: use a counter "i" = 1 to 5; if i < 4 print i, otherwise print 6 - i. This latter would be useful if, instead of simply printing the values indicated, you needed several commands within the loop; in this case, having a second loop is simply not practical.

User Avatar

Wiki User

14y ago

Still curious? Ask our experts.

Chat with our AI personalities

SteveSteve
Knowledge is a journey, you know? We'll get there.
Chat with Steve
ViviVivi
Your ride-or-die bestie who's seen you through every high and low.
Chat with Vivi
JordanJordan
Looking for a career mentor? I've seen my fair share of shake-ups.
Chat with Jordan

Add your answer:

Earn +20 pts
Q: How can you print 1 2 3 2 1 using for loop?
Write your answer...
Submit
Still have questions?
magnify glass
imp