gpt-4o-2024-08-06· OpenAI
WildChat-4.8M (AI2)
how i can do a loop from m to 1?
- User
how i can do a loop from m to 1?
- Assistant
To create a loop that counts down from
mto1, you can use different programming languages depending on your preference. Here are examples in a few popular languages:Python
pythonm = 10 # Example value for m for i in range(m, 0, -1): print(i)JavaScript
javascriptlet m = 10; // Example value for m for (let i = m; i >= 1; i--) { console.log(i); }Java
javaint m = 10; // Example value for m for (int i = m; i >= 1; i--) { System.out.println(i); }C++
cpp#include <iostream> using namespace std; int main() { int m = 10; // Example value for m for (int i = m; i >= 1; i--) { cout << i << endl; } return 0; }