Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

Why is my function looping in my Football management program?

 
Ranch Hand
Posts: 264
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

Making a team management program that I will hopefully create a GUI for (Down the road)

i have a few questions about the code:

1) How should a Python program be started? whats the usual way? i know there is a function thats like main in java. is it __main__ , is this just convention, i mean you dont have to have a main but it indicates where the
   program is running? Should you always name the starting function __main__?

2) When functions terminate does the program return to the position where the function was called?
   as i seem to have a loop running when i put a print statement in another function:


   

3) I think you guys said to me to never call functions from code at the end of other functions. Is that correct?
  so these lines are not great? There is a better way to design a program:
 

Sorry for all the questions, and also please if there is anything you find untowards please let me know

PS"Campbell I finsihed my course...No more SHORTS FOR ME!!! (Even though Summer has just started here)




 
Marshal
Posts: 65383
248
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

wayne brandon wrote:. . . PS"Campbell I finsihed my course...No more SHORTS FOR ME!!! (Even though Summer has just started here) . . .

Well done escaping. Summer has started here too, so we are having to wear clothes warmer than we needed in January.

Please tell us where you are going into an endless loop. It is a lot easier to help if you know the full details. My Python is well SHORT of being even rudimentary, but I start getting suspicious whenever I see while (true) ... in any language.
 
wayne brandon
Ranch Hand
Posts: 264
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
right so breaks are bad news and while trues are a no no too, noted.
 
wayne brandon
Ranch Hand
Posts: 264
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just to clarify, a while loop should always have a sentinel variable then?
like:



As far as the loop goes

this function is called from my main menu



createFixtures function is called from the else



the results are being drawn then loops endlessly

where in the UK are you? up north right?
weather in Cork was great today, hope we have the same summer as last year!!!

thanks for your help, muchly appreciated Campbell

 
Campbell Ritchie
Marshal
Posts: 65383
248
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There probably are circumstances where while (true) ... break; is actually useful programming, but I think beginners would do better to avoid that construct. You should be able to turn it into while (something) ... where “something” is the opposite of the condition you would use to call break; I am afraid it will require thought, but I know you are not SHORT of thinking abilities.
I would prefer all loops to have waht you call sentinel variables, yes.
What happens if you have two teams and go back to main menu (line 5)? Are you going into a recursion?
 
wayne brandon
Ranch Hand
Posts: 264
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
no everything is working fine till i go to start the league, then whatever is in there seems looped.
the print statement just loops
 
Can't .... do .... plaid .... So I did this tiny ad instead:
create, convert, edit or print DOC and DOCX in Java
https://products.aspose.com/words/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!