A clause in a single word
Instead of Mentre camminavo, ho incontrato Luca, Italians often just say Camminando, ho incontrato Luca, just like English Walking home, I met Luca. You already know the forms in -ando and -endo from the progressive. Here the gerundio stands on its own, without stare, and links two statements.
The three jobs in a sentence
The form does not tell you which job the gerundio has; the context does. Ask which English clause fits — while…, by…, since….
When: Both actions run at the same time. English: while, as, on. Italian puts nothing in front of the gerundio: not mentre camminando, simply camminando.
Tornando a casa, ho comprato il pane.
On my way home I bought some bread.
Guidando, ascolto sempre la radio.
When I'm driving I always listen to the radio.
Scendendo dall'autobus, sono scivolato.
Getting off the bus, I slipped.
How: The gerundio names the manner or the means. English: by + -ing. The gerundio alone carries the by: not per parlando, not con parlando.
Ha risposto sorridendo.
She answered with a smile.
Si impara una lingua parlando.
You learn a language by speaking it.
Ha comprato la macchina risparmiando per anni.
He bought the car by saving for years.
Why: The gerundio gives the reason. English: since, because. Here you often see essendo and avendo.
Essendo stanca, è andata a letto presto.
Since she was tired, she went to bed early.
Non avendo fame, ho saltato la cena.
Not being hungry, I skipped dinner.
Vedendolo così stanco, gli ho offerto un caffè.
Seeing how tired he was, I offered him a coffee.
The same subject
Typical mistake — two subjects
Gerundio
Camminando, il cane mi ha morso.
A dangling participle, as in English Walking home, the dog bit me: the dog is the one walking.
Full clause
Mentre camminavo, il cane mi ha morso.
While I was walking, the dog bit me.