[Tex/LaTex] Foreach loop for a string


how do I write

foreach triple ti in Q  do  
Q <- M 

in latex I have tried

\foreach \triple ti in {Q} {Q \gets M} 

but it doesnt work
I want the result to be displayed as follow it is a sort of an algorithm whriten in the report

Foreach Triple pattern ti ∈ Q Do

Q<- M "



   {MFS} $(Q,D)$\;
    \Input{ A failing Query Q = t1$\wedge$t2$\wedge$...$\wedge$tn and RDF Database D ;}
    \Output{An MFS denoted by Q* ;}
    Q $\gets$ Q* ; \\
    Q' $\gets$ Q* ; \\

    \caption{Find An MFS in a failing SPARQL Query}


I want this result


Best Answer

You need to use \ForEach{<condition>}{<stuff>}

enter image description here




  \caption{Find an \texttt{MFS} of a failing \texttt{SPARQL} query~$Q$}

    \Input{A failing query $Q = t_1 \wedge \dots \wedge t_n$; an \texttt{RDF} database $D$}
    \Output{An \texttt{MFS} denoted by $Q^*$}
    $Q^* \gets \emptyset$\;
    $Q' \gets Q$\;
    \ForEach{triple pattern $t_i \in Q$}{%
      $Q' \gets Q' - t_i$\;
      \If{$[[Q' \wedge Q^*]]_D \neq \emptyset$}{%
        $Q^* \gets Q^* \wedge t_i$\;


I've also defined a program called \FindAnMFS to obtain the outer block.