Here are several examples which should get you started:
With Do
:
a = 1;
Do[
a = a k,
{k, 1, 10}
]
a
With For
:
a = 1;
For[k = 1, k <= 10, k++,
a = a k
]
With While
:
a = 1;
k = 1;
While[k <= 10,
a = a k++
]
a
These are called procedural constructs and they are not what we usually use in Mathematica (though they're definitely necessary and advantageous in some situations)
You could also use Apply
:
Times @@ Range[10]
Or Fold
:
Fold[Times, 1, Range[10]]
Or recursive programming:
fact[1] = 1;
fact[n_] := fact[n - 1] n
fact[10]
If you are a beginner in Mathematica I recommend that you avoid For
for now in favour of Do
or While
. Use it only if:
You're facing one of the very rare cases when it really provides a simpler solution than the alternatives
You are translating code from a language which has an analogous for construct (C, C++, Java, etc.) and you want to minimize the risk of messing up something, at least during the first pass of translation
You are learning programming for the first time using Mathematica and you want to get familiar with this construct, which is very common in C-like languages. In this case it's good to get familiar with it, but I still don't recommend using it except when your explicit goal is to learn how to use For
.
Finally, based on your question it sounds like you might find this course very useful:
It is very old, but most of it still applies to current versions of Mathematica and gives a good foundation (especially if you don't have a lot of experience with other programming languages either).