Difference between revisions of "Break"
Jump to navigation
Jump to search
(Created page with "<c>break</c> is a keyword statement that jumps out of the innermost <c>for</c> or <c>while</c> loop. Category:Language [[Category:Keywords]...") |
Machiaworx (talk | contribs) (add introduce, example.) |
||
Line 1: | Line 1: | ||
<c>break</c> is a [[:Category:Keywords|keyword]] statement that jumps out of the innermost <c>[[for]]</c> or <c>[[while]]</c> loop. | <c>break</c> is a [[:Category:Keywords|keyword]] statement that jumps out of the innermost <c>[[for]]</c> or <c>[[while]]</c> loop. | ||
+ | If you want to stop a loop under a specific condition while processing a for or while statement, use the break statement. | ||
+ | |||
+ | Conversely, if you want to skip subsequent processing and enter the next loop, use the [[Continue]] statement. | ||
+ | |||
+ | == Example == | ||
+ | <ms> | ||
+ | str="I may use pencil." | ||
+ | result="" | ||
+ | for i in str | ||
+ | if i=="a" or i=="e" then break //aかeが出てきた時点で処理自体が終了する。 | ||
+ | result=result+i | ||
+ | end for | ||
+ | print result</ms> | ||
+ | |||
+ | ''' Output ''' | ||
+ | <pre>i m</pre> | ||
+ | |||
[[Category:Language]] | [[Category:Language]] | ||
[[Category:Keywords]] | [[Category:Keywords]] | ||
− | |||
− |
Latest revision as of 10:37, 10 April 2025
break
is a keyword statement that jumps out of the innermost for
or while
loop.
If you want to stop a loop under a specific condition while processing a for or while statement, use the break statement.
Conversely, if you want to skip subsequent processing and enter the next loop, use the Continue statement.
Example
str="I may use pencil."
result=""
for i in str
if i=="a" or i=="e" then break //aかeが出てきた時点で処理自体が終了する。
result=result+i
end for
print result
Output
i m