Page 2 of 2

Posted: Fri Oct 13, 2006 11:37 am
by bungytheworm
Best thing is to see when beginner makes hes first program :wink:
I tested your dice game. Im impressed your speed of learning. And idea of that game ain't bad either considering you just started learning. Keep on coding. 8)

Patz QuickBASIC Creations example of loop inside loop is cool one.
And you can actually do loop, inside of loop that is inside of loop :lol:

I also noticed you use DO LOOP instead of GOTO and thats a good sign.

Nice to notice also your way now, how you comment your code.
Every line dont need commenting, and in your program, Print"prints outs" with few comment lines explains enough. Keep on same way and youre in good "run" :wink:

Code: Select all

LOCATE 4, 11: PRINT "00000000000000000000000000"
LOCATE 5, 11: PRINT "00000000000000000000000000"
LOCATE 6, 11: PRINT "00000000000000000000000000"
LOCATE 7, 11: PRINT "00000000000000000000000000"
LOCATE 8, 11: PRINT "00000000000000000000000000"
LOCATE 9, 11: PRINT "00000000000000000000000000"
LOCATE 10, 11: PRINT "00000000000000000000000000"
LOCATE 11, 11: PRINT "00000000000000000000000000" 
Maybe you wana use FOR NEXT structure there.

Code: Select all

For x = 4 TO 11
     For y = 11 TO (how many zeros there is)
           LOCATE x, y : Print "0"; 
     NEXT y
Next x
It's not faster or anything, but in my opinion (and prolly many other) it's clearer to read and look.

Posted: Fri Oct 13, 2006 3:49 pm
by Patz QuickBASIC Creations
lurah wrote: Maybe you wana use FOR NEXT structure there.

Code: Select all

For x = 4 TO 11
     For y = 11 TO (how many zeros there is)
           LOCATE x, y : Print "0"; 
     NEXT y
Next x
It's not faster or anything, but in my opinion (and prolly many other) it's clearer to read and look.
Actually, this would be a good spot to use the STRING$ function.

Code: Select all

FOR X= 4 TO 11
LOCATE X,11
PRINT STRING$(26,"0")
NEXT X
When you want to have a bunch of text repeated, STRING$ works really well. Syntax is:

Code: Select all

STRING$(NumberToRepeat%, StringOfOneCharacter$)
OR
STRING$(NumberToRepeat%, ASCIICodeOfCharacter%)
So what STRING$(26,"0") returns is a string of "0" repeated 26 times, or "00000000000000000000000000". STRING$ saves coding and system speed, when the situation is appropriate.

Homework for tonight: Study the STRING$, LEN, STR$, and VAL functions - These are basic functions that people should be familar with.



P.S. There is one exception to using STRING$, and that is for when you are using spaces. Use SPACE$ instead. Syntax:

Code: Select all

SPACE$(NumberOfSpaces%)

Ex. SPACE$(14)="              "
It is roughly equivalent to using STRING$(NumberOfRepeats%," "). It saves program space.

Posted: Fri Oct 13, 2006 4:01 pm
by bungytheworm
Good point Patz QuickBASIC Creations (do you really had to have that long nice? :lol: )
I forgot STRING$ function. Alltho, i dont use it myself practically at all...dont know why :lol: