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 ?

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).

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.

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
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.