REM num% is going to be the number we are finding a factor of DIM num% num = 10 REM Now we're going to loop through all the numbers, from the number we are factoring minus 1 (in this case, 10-1=9) to 1, REM Our FOR/NEXT loop will have to have a step of -1 REM This is basically how we do math in our heads, we just don't think of that as FOR/NEXT loops. FOR i% = num%-1 TO 1 STEP -1 REM The MOD operator really just does division, except instead of returning the division result, it returns the remainer, which will only give us whole numbers. REM If the remainer is 0, then we know that the number divides evenly into 10, and therefore it is a factor-able number. remainer% = num% MOD i% IF remainer% = 0 THEN REM If this were calculating a common factor, I would want a nested IF statement here to calculate the second remainer PRINT "Highest factor of"; num%; "is"; i% REM We have our highest factor of the number, so we can jump out of this loop now EXIT FOR END IF NEXT i%
FOR i% = 1 TO 10 PRINT i% NEXT i%
FOR i% = 1 TO 10 STEP 1 PRINT i% NEXT i%
1 2 3 4 5 6 7 8 9 10
1 3 5 7 9
FOR i% = 0 TO 10 STEP 2 PRINT i% NEXT i%
0 2 4 6 8 10
FOR i% = 10 to 0 STEP -2 PRINT i% NEXT i%
10 8 6 4 2 0
FOR i% = 1 TO 10 my_array%(i%) = i% * 2 PRINT "my_array%("; i%; ") = "; my_array%(i%) NEXT i%
my_array%( 1 ) = 2 my_array%( 2 ) = 4 my_array%( 3 ) = 6 my_array%( 4 ) = 8 my_array%( 5 ) = 10 my_array%( 6 ) = 12 my_array%( 7 ) =14 my_array%( 8 ) = 16 my_array%( 9 ) = 18 my_array%( 10 ) = 20
INPUT "Give me a number: ", number% PRINT "Number is"; number%
DIM cool_numbers%(1 TO 3) FOR i% = 1 TO 3 INPUT "Give me a cool number: ", cool_numbers%(i%) NEXT i%
DIM an_array_with_numbers%(1 TO 500) REM Since we know we will be comparing all the numbers, we will want to save the one that is the highest. REM To start, we will want to store the first number in the array, since we don't have a way of knowing the lowest number (so we can't just set it to 0) DIM largest_number% = an_array_with_numbers%(1) REM Notice that we are skipping the 1st index, because we have already stored it. There is no harm in doing a comparison of it, though, since a number cannot be greater or less than itself. FOR i% = 2 TO 500 num% = an_array_with_numbers(i%) IF num% > largest_number% largest_number% = num% END IF NEXT i% PRINT "Largest number: "; largest_number
I have been a qbasic programmer since 2000, creating games, minor libraries and various small programs. I have experience using interrupts, graphics, file input/output, the mouse cursor, and using libraries. I have also learned FreeBASIC, QB64, c/c++, python, lua, php and html.
I do not claim to be an absolute authority in any language, but I don't mind looking things up and learning with you.
I have been programming in *Basic dialects since 2000, as mentioned in my expertise. After a year of QBasic, I learned C and C++, and dabbled a little in ASM (I don't program in ASM - I literally just played around to see how things work). When QB64 and FreeBASIC were released, I played with those languages. At the time, FreeBASIC offered more functionality and I sided with that language for a while. During that time, while I was learning new languages, that I would see what scripting languages are available, where I took up python and lua. I started to notice a staleness to QB64's development (which I kept tabs on from time to time), and am now trying to be active in it's community and maybe in it's development in the future.
Currently, I am only active on the QB64.net forums, but I appear on occasion on FreeBASIC.net's forums as well.
Highschool - 2007