School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 307,095 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 2,006 people online right now. Registration is fast and FREE... Join Now!




break statements

 

break statements

cmb11

18 Oct, 2009 - 05:47 PM
Post #1

New D.I.C Head
*

Joined: 18 Oct, 2009
Posts: 1

Are break statements & 'hit any key to stop loop' the same?

User is offlineProfile CardPM
+Quote Post


KYA

RE: Break Statements

19 Oct, 2009 - 10:55 AM
Post #2

#include <nerd.h>
Group Icon

Joined: 14 Sep, 2007
Posts: 11,499



Thanked: 508 times
Dream Kudos: 2875
Expert In: C, C++, Java

My Contributions
In what context?

You'll have to actively wait for a key to break (which once the key is pressed you'd do since the loop, I assume, is infinite in nature).
User is online!Profile CardPM
+Quote Post

Tshiknn

RE: Break Statements

19 Oct, 2009 - 06:42 PM
Post #3

New D.I.C Head
*

Joined: 18 Oct, 2009
Posts: 18



Thanked: 2 times
My Contributions
QUOTE(cmb11 @ 18 Oct, 2009 - 05:47 PM) *

Are break statements & 'hit any key to stop loop' the same?


In most languages, the break statement is the program's way of exiting a loop. To answer your question, no. Assuming you are familiar with basic 'for' and 'while' loops in Python, the following code will print a number until the number is thirteen.

CODE
i = 0
while True:
    if i == 13:
        print "Unlucky Number!"
        break
    else:
        print i,
        i += 1


This program will produce the following output:
CODE
0 1 2 3 4 5 6 7 8 9 10 11 12 Unlucky Number!



User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/21/09 11:41AM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month