(* Do not save output when exit from Mathematica *)
SetOptions[EvaluationNotebook[],NotebookEventActions -> {"WindowClose":> FrontEndExecute[FrontEndToken["DeleteGeneratedCells"]]}];

Programming

Loops

(* Do loop *)
Do[Print[n^2],{n,4}]

(* Do with steps = 2 *)
Do[Print[n^2],{n,-3,5,2}]

(* For loop - c-like loop*)
For[i=0, i<4,i++,Print[i]]

(* comman delimits the parts of For, and semicolon delimits the parts of procedures *)
For[i= 1; t=x, i^2<10, i++, t=t^2+i;Print[t]]

(* While loop *)
n=1; While[n<4, Print[n]; n++]

(* Nest *)
Nest[f,x,3]

Modules

f[x0_] := Module[{ x= x0}, while[x>0, x=Log[x]]; x]

f[2.0]

(* Variables inside the module are local *)
(* This function defines a slightly modified factorial *)
myFun[x_] := Module[{f,n},f[1]=1; f[n_]:=x+n f[n-1]; f[5]]

myFun[0]

myFun[2]

With

(* Replaces variables with the values *)
f[x_]:= With[{y=x+1},1+y+y^2]

f[a]