|
Post by Eric on Jul 17, 2002 10:31:29 GMT
i was wondering if anyone can help me....i am trying to write a program that >prints the following output: >* >** >*** >**** >***** >****** > >i tried to write it as follows: > >i=o >n=6 >do unitl (i<n) > print "*" > i=i+1 >loop >stop >end > >I know i am missing an instruction but i can't think >what it is. because my >output is only print 1 * on each line. Can you give me >some advice on this. >and then also if i add color to it, how would i make it >blink? Any help >would be appreciated.....thanks
|
|
|
Post by programmer on Jul 17, 2002 19:26:18 GMT
well im not sure wuts rong with your program but heres how i would do it
====================================== SCREEN 12 CLS FOR q = 0 TO 15 COLOR q LOCATE 1 SLEEP 1 PRINT "*" PRINT "**" PRINT "***" PRINT "****" PRINT "*****" PRINT "******" NEXT ======================================= that makes it blink 16 colors
|
|
|
Post by brisray on Jul 18, 2002 4:24:47 GMT
The mistake is the line PRINT "*"
Without a ";" on the end the PRINT statement will add a CRLF (carriage return + line feed).
To do what to want it to do you could use :-
CLS Num = 10 FOR Counter = 1 TO Num FOR Count = 1 TO Counter PRINT "*"; NEXT Count PRINT NEXT Counter
Funnily enough I made a mistake when testing this and put :-
CLS Num = 10 FOR Counter = 1 TO Num FOR Count = 1 TO Count PRINT "*"; NEXT Count PRINT NEXT Counter
which also works
Though a much simpler solution is to use the STRING$ command :-
FOR Count = 1 TO 10 PRINT STRING$(Count, "*") NEXT Count
or
FOR Count = 1 TO 10 PRINT STRING$(Count, CHR$(42)) NEXT Count
Ray
|
|
|
Post by TdinoW on Sept 21, 2002 1:59:00 GMT
I copied a Mario code and it doesnt work HERE IS THE PROBLEM:
IF tr <22 THEN IF MID$(L$(tr), tc, 1) = "[] THEN tr = otr: ELSE g = INT(RND*2+1)
IT asks for a THEN statment but I dont know were. I just dont know what the problem is, can you help?
|
|
|
Post by brisray on Sept 21, 2002 5:11:11 GMT
This is one reason why it's not a good idea to put multiple programming lines on one using : It looks like it's saving space but it isn't worth the hassle it can cause.
Having said that the cause is really quite simple. Its the MID$(L$(tr), tc, 1) = "[] part. There is no terminating " to the string literal.
Try
IF tr < 22 THEN IF MID$(L$(tr), tc, 1) = "[" THEN tr = otr ELSE g = INT(RND * 2 + 1)
Now you'll get another error message, this time saying "Block IF without END IF." This is because the code should look like this :-
IF tr < 22 THEN IF MID$(L$(tr), tc, 1) = "[" THEN tr = otr ELSE g = INT(RND * 2 + 1) END IF
Ray
|
|
|
Post by brisray on Sept 21, 2002 5:32:34 GMT
Just to open another can of worms. It's about the variable names in the code you provided.
Some people say that using short variable names is preferable because it cuts down on spelling mistakes and makes typing the program faster.
To my mind, these people have never had to debug programs that someone else has written using this format nor have they revisited code they've written weeks, months or years earlier.
It really is easier if you use longer, more English (or whatever language) names for variables. tr could be anything or nothing whereas names like SpriteXPosn, NatInsNo or SocSecNo at least gives a clue of what the variable does and what it should contain.
Ray
|
|
pebe
Junior Member
Posts: 39
|
Post by pebe on Sept 21, 2002 15:42:35 GMT
I'll agree with that 100%, brisray.
The other very necessary requirement is to document sections with a ' or REM, explaining them. Saves hours of work later on when you revisit.
|
|