Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
loops & arrays
#11
winhack:

Heres a much cleaner way of doing it Smile
Code:
CLS

DIM a$(1 TO 12)

FOR i% = 1 TO 12
   READ a$(i%)
NEXT

FOR i% = 1 TO 12
   PRINT a$(i%)
NEXT

DATA "jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"
Reply
#12
Even cleaner would be to combine the two for/next loops.

Code:
qbasic
for i = 1 to 12
read a$(i)
print a$(i)
next
Reply
#13
Yeah. But its kinda funny to see read and print in the same loop. Seriously the reason i kept the two loops separate was that he may not want to use the "READ" statement.
Reply
#14
TYPE MonthType

Name AS STRING
Days AS INTEGER

END TYPE

DIM Month AS MonthType

FOR i = 1 to 12
READ a$, b%
Month(i).name = a$
Month(i).days = b%
NEXT i

FOR m = 1 to 12
Print Month(m).name; " has "; str$(Month(m).Days);" days."
NEXT m

END

DATA "jan", 31
DATA "feb", 28
DATA "mar", 31
DATA "apr", 30
DATA "may", 31
DATA "jun", 30
DATA "jul", 31
DATA "aug", 31
DATA "sep", 30
DATA "oct", 31
DATA "nov", 30
DATA "dec", 31
Reply
#15
could you have done

Code:
FOR i = 1 to 12
READ Month(i).name, Month(i).days = b%
NEXT i

instead?
[Image: sig.php]
Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.
Reply
#16
Hrm DATA always makes me nervous... probably because I never liked how you coudln't pick when and where to start loading the data -from-... that's probably just me though. :normal:
nce upon a time there crept through the looking-glass a curious child whose manners were not very good. Perhaps a little clever, yes, but given to spying, and sneaking, and going through dead men's pockets... [cloudmakers]
Reply
#17
...you can...
Reply
#18
In case you didn't notice it, click on "can" in Plasma's post for a link to the explanation.

Also see Zaps comments in your other thread.
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)
Reply
#19
Thanks - I think I will probably start using files once I get the hang of them. Big Grin
nce upon a time there crept through the looking-glass a curious child whose manners were not very good. Perhaps a little clever, yes, but given to spying, and sneaking, and going through dead men's pockets... [cloudmakers]
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)