Differences between revisions 1 and 2
Revision 1 as of 2018-09-28 14:11:41
Size: 248
Comment:
Revision 2 as of 2018-09-28 14:20:27
Size: 860
Comment:
Deletions are marked like this. Additions are marked like this.
Line 7: Line 7:

----
== 制御構造:反復:While ==


 * ~のあいだ繰り返す(while, else)

 * 文法

{{{#!highlight python
while expression:
    suite...
[else:
    suite...]
}}}

 * while は「~のあいだ」を意味します



{{{#!highlight python
n = 0
while n < 10:
    print( n )
    n += 1
}}}


{{{#!highlight python
for n in range(10):
    print( n )
}}}


 * else がある場合は,ループの最後に else節を実行する
  * breakした場合は...

{{{#!highlight python
n = 0
while n < 10:
    print( n )
    n += 1
else:
    print( "END" )
}}}


制御構造:反復: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( "END" )

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