Looping Coding Logic

Questions about programming languages and debugging
Post Reply
User avatar
maboroshi
Dr. Mab
Dr. Mab
Posts: 1624
Joined: 28 Aug 2005, 16:00
18

Looping Coding Logic

Post by maboroshi »

Ive discovered Looping on a whole new plain. Probably not new to a lot of you but here it is

Code: Select all

def for10():
    for i in range(10):
        print i
        
def loopWhileContinue():
    while 1:
        print "1-"
        break
    for i in range(5):
        print str(i) + "-"
        
while 1:
    print "1+"
    loopWhileContinue()
    for10()

User avatar
n3rd
Staff Member
Staff Member
Posts: 1474
Joined: 15 Nov 2005, 17:00
18
Location: my own perfect world in ma head :)
Contact:

Post by n3rd »

err what is the use of this loop :oops:
[img]http://img580.imageshack.us/img580/8009/userbar2k.png[/img]

User avatar
computathug
Administrator
Administrator
Posts: 2693
Joined: 29 Mar 2007, 16:00
17
Location: UK
Contact:

Post by computathug »

Ok i dont use python but by looking at the code i am guessing that it is taking a float and converting to a string and looping the program to +1 continuously until it reaches (' ') which would be infinative.

.....i was working with looping numbers in ruby and it looks similar :-k

looking again the loop is adding the string in reverse too, ok mabs

explain :lol:

User avatar
maboroshi
Dr. Mab
Dr. Mab
Posts: 1624
Joined: 28 Aug 2005, 16:00
18

Ok

Post by maboroshi »

Ok its just nested looping using functions... so a loop calling multiple loops

the code could have been written like this to

Code: Select all

while 1:
    print "1+"
    while 1:
        print "1-"
        break
    for i in range(5):
       print str(i) + "-"
    for i in range(10):
        print i
while 1: #loops infinite which is the main loop and prints "1+" to the console

the second while 1: prints 1- to the console then breaks out of that loop to continue to the rest of the code which is

for i in range(5) which prints out the numbers 0 -4 with a minus sign - then continues to for i in range(10) and prints out the numbers 0 -9 then the loop starts over doing the same in that sequence indefinitley

I was just exploring nested loops and was half asleep when I wrote it haha it really does nothing its just gibberish code to explore an idea while I was near passed out anyway

*cheers

Maboroshi

Post Reply