0

For next loop in qbasic?
hey i am taking a beginner's course in programming and i have been asked to tackle this question using the for loop its like i have to write a program that will print the numbers as follows..
1
12
123
1234
12345
123456

how can i do it fellows ?

4
Contributors
3
Replies
5
Views
6 Years
Discussion Span
Last Post by Unseen Machine
1

When asking for help with homework, it's a good idea to explain what you've tried.

Here you want to use a for/next loop to print "the numbers". So show us some QBasic code that you wrote to do it (surely the loop itself cannot be all that mysterious).

Then it will be possible for readers to chime in with suggestions on the part that you are having difficulty with (without rehashing the proper syntax for easy things like a for/next loop that would be in your documentation).

0

You want to treat this exercise as in strings rather than numbers. Take each successive occurrence of your loop variable, as a string, and add (append) it to a string which you have previously set to null. I leave the actual coding to you, but you will have to trim off the leading space which the STR$ function adds.

0

Here's a version in a DO:Loop for you to convert if you still need it.

DO

  '// If you dont want the spaces us LTRIM$
  NumberString$ = NumberString$ + LTRIM$(STR$(i%))

  '// If you do want the spaces, use this version
  'NumberString$ = NumberString$ + STR$(i%)

  PRINT NumberString$
  i% = i% + 1

LOOP UNTIL i% = 10
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.