Can we use loop functions(for, while,do-while) in tableau calculated Fields? If we can, how can we use these functions in calculated fields and how can we initialize the variables which are declared in these functions?
No, we can't use the loop function in Tableau. There are few alternatives to do some calculations like that, using PREVIOUS_VALUE and other table calculations, but there are no loop functions in Tableau.
Because Tableau is not meant to be a data processing tool, rather than a data visualization tool. It means, Tableau engine is very good to process data, but only to perform "query-like" operations.