473,503 Members | 1,768 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to do the break??

9 New Member
i doing a proram where i will first ask the user to key in the datas they have, Lets 3, then i will on ly allow them to key in 3 datas.

after that , ithe 3 datas will be add together, giving the total sum automatically.

This is the program that i write:

total=0
aCounter=0
a=raw_input("insert a:\t")
a=float(a)
while a!=-1:
total=total+a
aCounter=aCounter+1
a=raw_input("insert a:\t")
a=float(a)
if aCounter!=0:
add=float(total)/aCounter
n=float(n)/aCounter
print"total X ia",add
if a==n:
break

but when i run , ii state there " break outside loop",. Can anyone tell me how to do?? thank you.
Sep 22 '06 #1
6 2978
Bellum
23 New Member
The actual program is tabbed, isn't it? Could you do that, I can't really tell whats going on otherwise. >.>


Well, I don't know. I might still not be able to tell what's going on, but it will help.
Sep 23 '06 #2
fullmoon84
9 New Member
thanks for ur help.
Sep 23 '06 #3
bartonc
6,596 Recognized Expert Expert
In future, please read guidlines so your posts look like this:

Expand|Select|Wrap|Line Numbers
  1. total=0
  2. aCounter=0
  3. nDataPoints = int(raw_input("How many data points?:\t"))
  4.  
  5. while 1:
  6.     aCounter = aCounter + 1
  7.     a = float(raw_input("insert data point:\t"))
  8.     total = total + a
  9.     if aCounter == nDataPoints:
  10.         break
  11. average = total/aCounter
  12. print "Total = %f, Average = %f:" %(total, average)
  13.  
Otherwise, nobody can see the structure of you code.
Sep 23 '06 #4
fullmoon84
9 New Member
ok.Thank you
Sep 23 '06 #5
Jmlman
2 New Member
I think that the break command is not working because it is placed inside an if statement, whereas it should be placed in a loop.
Oct 3 '06 #6
bartonc
6,596 Recognized Expert Expert
I think that the break command is not working because it is placed inside an if statement, whereas it should be placed in a loop.

A better way to do that is:

Expand|Select|Wrap|Line Numbers
  1. for i in range(nDataPoints):
  2.     a = float(raw_input("insert data point:\t"))
  3.     total = total + a
  4.  
you can use i which counts for zero to nDataPoints - 1 inside you loop if you need to.
Oct 3 '06 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

5
2524
by: Ann | last post by:
I have trouble sometimes figuring out where break and continue go to. Is there some easy way to figure it out, or a tool? TIA Ann
5
33683
by: viza | last post by:
Hi! Suppose I have int i,j,k; for(i=0;i<I;++i){ /* loop 1 */ for(j=0;j<J;++j){ /* loop 2 */ for(k=0;k<K;++k){ /* loop 3 */ if(test){
25
3881
by: chunhui_true | last post by:
In <<expert c>>I know the break in if wich is scoped in switch is break the switch,like: switch c case 1: if(b){ break; } ...... But like this: while(a){
5
40192
by: tony collier | last post by:
To break out of a loop i have seen some people use RETURN instead of BREAK I have only seen RETURN used in functions. Does anyone know why RETURN is used instead of BREAK to kill loops?
55
3659
by: Ennixo | last post by:
hi, do you know where i can find some ebooks or websites talking about C# optimisation ? for exemple, i just learned that ++i is faster than i++. i would like to know more about the things...
2
8718
by: yyhhjj | last post by:
I created a test program to implement an iterator. First, I used 'yield break' in the iterator, it worked normally. Then, I simply used 'break' in the places of 'yield break', it still worked...
3
6249
by: Barbara Alderton | last post by:
I recently wrote an ASP.NET app that used user controls. I produced a printer-friendly output form. One requirement was a pagebreak between one part of the form and another. I had no problem...
2
4197
by: ichor | last post by:
hi i want to add a conditional break in my vb.net code. like we could in vb6. for example if the counter = 10 then break at that point. kindly let me know if thats possible in vb.net Ichor
26
10177
by: Alexander Korsunsky | last post by:
Hi! I have some code that looks similar to this: -------------------------------------------- char array = "abcdefghij"; for (int i = 0; i < 10; i++) {
7
11088
by: =?Utf-8?B?aXdlYg==?= | last post by:
Can we set page breaks in ASP Pages dynamically based on the data being populated? Akshay.
0
7076
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7274
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7323
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6984
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7453
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5576
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5005
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4670
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
377
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.