next up previous contents
Next: nested loops Up: 迴圈 Previous: for loop   Contents

do...while loop

  1. 流程圖

    \begin{tikzpicture}[node distance=1.5cm]\setlength \baselineskip{1ex}
\node [input,name=input] {};
\node [block, below of=input] (code) {block code};
\node [decision, below of=code] (decision) {condition?};
\node [cir,below of=decision] (sum) {};
\path [line] (input) -- (code);
\path [line] (code) -- (decision);
\path [line] (decision) -- node[right]{false}(sum);
\path [line] (decision.west) -\vert node[above right] {true} ($(decision.west) + (-1,0)$) \vert- (code.west);
\end{tikzpicture}

  2. 語法
    do {
       statement(s);
    
    }while( condition );
    
  3. 範例
    #include <stdio.h>
     
    int main ()
    {
       /* local variable definition */
       int a = 10;
    
       /* do loop execution */
       do
       {
           printf("value of a: %d\n", a);
           a = a + 1;
       }while( a < 20 );
     
       return 0;
    }
    



2015-01-16