[Tutor] [SOLVED] Different between pass & continue

M. Bashir Al-Noimi mbnoimi at gmx.com
Tue May 18 22:00:34 CEST 2010


Thanks

On 18/05/2010 02:20 م, Steven D'Aprano wrote:
> On Tue, 18 May 2010 10:34:16 pm M. Bashir Al-Noimi wrote:
>    
>> Hi All,
>>
>>
>> I couldn't understand the difference between pass and continue
>> keywords, could you explain to me?
>>      
>
> "pass" is a do-nothing statement. It literally does nothing.
>
> "continue" is only allowed inside a for-loop or while-loop, and
> means "jump to the start of the loop". It is related to "break".
>
> Consider the difference between these three loops:
>
>
>    
>>>> for x in (1,2,3):
>>>>          
> ...     print(x)
> ...     pass
> ...     print(x, "again")
> ...
> 1
> 1 again
> 2
> 2 again
> 3
> 3 again
>    
>>>>
>>>> for x in (1,2,3):
>>>>          
> ...     print(x)
> ...     continue
> ...     print(x, "again")
> ...
> 1
> 2
> 3
>    
>>>>
>>>> for x in (1,2,3):
>>>>          
> ...     print(x)
> ...     break
> ...     print(x, "again")
> ...
> 1
>    
>>>>          
>
>
>    

-- 
Best Regards
Muhammad Bashir Al-Noimi
My Blog: http://mbnoimi.net

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100518/4c354eba/attachment.html>


More information about the Tutor mailing list