Differences between revisions 2 and 4 (spanning 2 versions)
Revision 2 as of 2018-09-28 14:20:27
Size: 860
Comment:
Revision 4 as of 2018-09-28 14:32:46
Size: 938
Comment:
Deletions are marked like this. Additions are marked like this.
Line 9: Line 9:
== 制御構造:反復:While == == 制御構造:条件が成立している間の反復:While ==
Line 12: Line 12:
 * ~のあ繰り返す(while, else)  * 条件が成立してる間,繰り返す(while, else)
Line 50: Line 50:
    print( "END" )     print( "無事,終了しました" )


制御構造:条件が成立している間の反復:While

  • 条件~が成立している間,繰り返す(while, else)
  • 文法

   1 while expression:
   2     suite...
   3 [else:
   4     suite...]
  • while は「~のあいだ」を意味します

   1 n = 0
   2 while n < 10:
   3     print( n )
   4     n += 1

   1 for n in range(10):
   2     print( n )
  • else がある場合は,ループの最後に else節を実行する
    • breakした場合は...

   1 n = 0
   2 while n < 10:
   3     print( n )
   4     n += 1
   5 else:
   6     print( "無事,終了しました" )

SoftEng: Python/Lang/ControlStructure/Loop/WhileStatement/Contents (last edited 2018-10-04 05:30:33 by TadashiIijima)