[Tutor] Repeating a routine
Brian Gustin
brian at daviesinc.com
Wed Feb 22 18:14:12 CET 2006
yeah GOTO , in basic (I used to write software in Commodore BASIC
myself) is similar to a for or while loop -
In BASIC, you would write a program, *including* line numbers thus:
10 a=32
20 b="hello"
30 print a
40 print b
50 a=a-1
60 if a > 0 goto 20
70 end
(It's probably not 100% syntactically correct, but the general idea is
it would print "hello" 33 times and then end..)
in python, you would do :
a=32
b=hello
c=0
while c <= a:
print b
c = c+1
for the same results- that's what GOTO in BASIC would be used for
BASIC also had subroutines, which are GOSUB, which equate to perl's sub,
php's function, or python's def
Just my 2 cents worth :)
Bri!
Pawel Kraszewski wrote:
> Dnia środa, 22 lutego 2006 12:43, John Connors napisał:
>
>
>
>>I know goto and gosub are evil, bad habits but I'm starting to miss them.
>
>
> You SHOULD miss them. GOSUB is called a function call in Python (you call a
> function by its name, rather than by its starting line number)
>
> Someone misinformed you: GOSUB is perfectly good. It's GOTO that's evil.
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
> !DSPAM:43fc986c278471677385699!
>
>
More information about the Tutor
mailing list