Posts: 3,616
Threads: 287
Joined: Jan 2003
This is probably a simple problem, but here:
Code: SCREEN 13
DIM map(1 TO 10, 1 TO 10)
DATA 1,1,1,1,1,1,1,1,1,1
DATA 1,0,0,0,0,0,0,0,0,1
DATA 1,0,0,0,0,0,0,0,0,1
DATA 1,0,0,0,0,0,0,0,0,1
DATA 1,0,0,0,0,0,0,0,0,1
DATA 1,0,0,0,0,0,0,0,0,1
DATA 1,0,0,0,0,0,0,0,0,1
DATA 1,0,0,0,0,0,0,0,0,1
DATA 1,0,0,0,0,0,0,0,0,1
DATA 1,1,1,1,1,1,1,1,1,1
FOR y = 1 TO 10
FOR x = 1 TO 10
READ z
map(x, y) = z
NEXT
NEXT
FOR y = 1 TO 10
FOR x = 1 TO 10
IF x = 10 THEN
PRINT map(x, y)
ELSE
PRINT map(x, y);
END IF
NEXT
NEXT
How do I get it to stop printint spaces in between each number?
f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Posts: 6,419
Threads: 74
Joined: Mar 2002
Code: PRINT LTRIM$(STR$(variable%))
Posts: 3,368
Threads: 195
Joined: Jan 2003
LTRIM$(STR$(map(x, y)))
or rtrim$......................
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."
Visit www.neobasic.net to see rubbish in all its finest.
Posts: 3,343
Threads: 83
Joined: Mar 2003
Nope, LTRIM$. A space is reserved at the front of the string equiv of a number for a -ve sign.
Posts: 3,616
Threads: 287
Joined: Jan 2003
Ah, now I remember reading that! I never figured out why it added a space.
f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Posts: 309
Threads: 15
Joined: Jul 2003
By putting a PRINT after the FOR x loop, you can save yourself the IF ... THEN ... ELSE.
Code: FOR y = 1 TO 10
FOR x = 1 TO 10
PRINT map(x, y);
NEXT
PRINT
NEXT
hrist Jesus came into the world to save sinners, of whom I am first.(I Timothy 1:15)
For God so loved the world, that He gave His only begotten Son,
that whoever believes in Him should not perish, but have eternal life.(John 3:16)
Posts: 3,616
Threads: 287
Joined: Jan 2003
Quote:By putting a PRINT after the FOR x loop, you can save yourself the IF ... THEN ... ELSE.
Code: FOR y = 1 TO 10
FOR x = 1 TO 10
PRINT map(x, y);
NEXT
PRINT
NEXT
I just needed to test whether a newline was needed, i.e. end of a row of the map. Notice that I put ";" on one of the PRINTs?
f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Posts: 95
Threads: 8
Joined: Nov 2003
they both do the same thing, its just that SCM does it a cleaner way.
yours goes through the x loop, and if x = 10, then it prints the number and then goes to the next line.
SCM's goes through the x loop, and then after it has gone through, it goes to the next line.
now if the x loop went to a number bigger than 10, but you still wanted it to print a new line at the 10th loop, then your way would be the only way.
url=http://webberboy.no-ip.com]Fine Hand-Crafted Pens[/url]
Pneumonoultramicroscopicsilicovolcanoconiosis: Noun, A hypothetical, invented disease of the lungs, caused by inhaling mineral or metallic dust, such as silicon and quartzite, over a long period.]
Posts: 309
Threads: 15
Joined: Jul 2003
I thought mine would be more efficient, because it avoids the IF statements being repeated. After I thought about it, I realized I had traded 10 IF's for 1 PRINT, and Print's are slow. I tested it both ways and found the performance to be the same. I agree that mine looks cleaner, but it doesn't work any better.
hrist Jesus came into the world to save sinners, of whom I am first.(I Timothy 1:15)
For God so loved the world, that He gave His only begotten Son,
that whoever believes in Him should not perish, but have eternal life.(John 3:16)
Posts: 6,419
Threads: 74
Joined: Mar 2002
I'm a geek
Code: FOR y = 1 TO 10
FOR x = 1 TO 10
LOCATE y,x
PRINT map(x, y)
NEXT
NEXT
|