Author Topic: Basics of QB64 - Looping around  (Read 3814 times)

0 Members and 1 Guest are viewing this topic.

This topic contains a post which is marked as Best Answer. Press here if you would like to see it.

FellippeHeitor

  • Guest
Basics of QB64 - Looping around
« on: September 06, 2020, 10:17:50 am »
Computers are great at doing repetitive tasks for us. Here's how you can loop in BASIC.


Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Basics of QB64 - Looping around
« Reply #1 on: September 06, 2020, 10:44:30 am »
Oh wow, didn't know QB64 has _CONTINUE and can use it in any loop structure.

FellippeHeitor

  • Guest
Re: Basics of QB64 - Looping around
« Reply #2 on: September 06, 2020, 10:55:05 am »
Glad there was something new for you, bplus!

_CONTINUE was added back in 2017 actually. It made its debut in v1.2.
« Last Edit: September 06, 2020, 10:57:46 am by FellippeHeitor »

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: Basics of QB64 - Looping around
« Reply #3 on: September 06, 2020, 10:59:13 am »
I had forgotten about _CONTINUE!

Good job, Fellippe as always. You know, for a non-native English speaker your English is very good and clearly understandable.

Thanks again for keeping the tutorials coming.

- Dav

FellippeHeitor

  • Guest
Re: Basics of QB64 - Looping around
« Reply #4 on: September 06, 2020, 10:59:52 am »
Quote
Good job, Fellippe as always. You know, for a non-native English speaker your English is very good and clearly understandable.

Thanks, Dav!

Offline wiggins

  • Newbie
  • Posts: 34
    • View Profile
Re: Basics of QB64 - Looping around
« Reply #5 on: September 07, 2020, 07:44:51 pm »
I have not used the new commands, so this is really helpful to me.

Very good video. 

Thanks!!!

FellippeHeitor

  • Guest
Re: Basics of QB64 - Looping around
« Reply #6 on: September 07, 2020, 07:51:11 pm »
I have not used the new commands, so this is really helpful to me.

Very good video. 

Thanks!!!

Glad you enjoyed it, wiggins.

Offline JohnUKresults

  • Newbie
  • Posts: 40
    • View Profile
Re: Basics of QB64 - Looping around
« Reply #7 on: September 08, 2020, 07:20:04 am »
Thanks Fellippe. Good to know about _Continue! Could prove useful.

Offline OldMoses

  • Seasoned Forum Regular
  • Posts: 469
    • View Profile
Re: Basics of QB64 - Looping around
« Reply #8 on: September 12, 2020, 08:10:39 pm »
_CONTINUE is my new toy, I think I have some work for it to do, Thank you.

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Basics of QB64 - Looping around
« Reply #9 on: September 14, 2020, 04:36:58 pm »
Well done Fellippe!
I think that these your efforts to introduce to QB64 programming can be very useful for beginners to programming and beginners to QB64.
It maybe is good thing to group them into a separate section of the QB64 website.
Waiting feedbacks from veterans of the QB64.
Programming isn't difficult, only it's  consuming time and coffee

Marked as best answer by on June 29, 2024, 08:37:14 pm

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Basics of QB64 - Looping around
« Reply #10 on: September 14, 2020, 04:51:45 pm »
  • Undo Best Answer
  • _CONTINUE is a good shortcut to modify your code!

    all that you can get with _continue you can get with a IF THEN END IF!
    Surely in a large code it is simpler to use
    Code: QB64: [Select]
    1. IF condition THEN _CONTINUE
    2. block of code
    than
    Code: QB64: [Select]
    1.  IF NOT  condition THEN
    2. block of code
    and these previous two way are more flexible than
    Code: QB64: [Select]
    1. IF condition THEN label [GOTO label]
    Programming isn't difficult, only it's  consuming time and coffee

    Offline OldMoses

    • Seasoned Forum Regular
    • Posts: 469
      • View Profile
    Re: Basics of QB64 - Looping around
    « Reply #11 on: September 14, 2020, 08:01:02 pm »
    _CONTINUE is a good shortcut to modify your code!

    I just went through and replaced all my:

    <loop structure>
        IF condition THEN
            block of code
        END IF
    <end loop structure>

    with:

    <loop structure>
        IF <NOT> condition THEN _CONTINUE
        block of code
    <end loop structure>

    It shaved off over a couple dozen END IFs in my ap without changing the action. It just requires an opposite condition test.

    Doesn't really reduce typing, but cleans up some indentation nesting, which I did find desirable. Leaves a bit more space for comments.
    « Last Edit: September 14, 2020, 08:04:38 pm by OldMoses »

    Offline SMcNeill

    • QB64 Developer
    • Forum Resident
    • Posts: 3972
      • View Profile
      • Steve’s QB64 Archive Forum
    Re: Basics of QB64 - Looping around
    « Reply #12 on: September 14, 2020, 09:08:07 pm »
    I just went through and replaced all my:

    <loop structure>
        IF condition THEN
            block of code
        END IF
    <end loop structure>

    with:

    <loop structure>
        IF <NOT> condition THEN _CONTINUE
        block of code
    <end loop structure>

    It shaved off over a couple dozen END IFs in my ap without changing the action. It just requires an opposite condition test.

    Doesn't really reduce typing, but cleans up some indentation nesting, which I did find desirable. Leaves a bit more space for comments.

    Only thing to remember:

    IF NOT (condition) THEN _CONTINUE....  may not be the same as IF (condition) THEN...(code stuff)

    For example:

    IF x AND y THEN
        do stuff
    END IF

    Now, if x = 4, and y = 2, then x AND y = 2, so you DO STUFF.

    Now let’s try the other.

    IF NOT (x AND y) THEN _CONTINUE
    do stuff...

    In this case, (x AND y) end up evaluating to 2, same as above, so NOT 2 gives us -3.  -3 is still regarded as a TRUE evaluation, so you now _CONTINUE and skip doing your stuff.

    The *ONLY* time you can safely interchange the two methods, is when you’re dealing with binary results.  (0 and -1 only)

    https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

    Offline TempodiBasic

    • Forum Resident
    • Posts: 1792
      • View Profile
    Re: Basics of QB64 - Looping around
    « Reply #13 on: September 15, 2020, 09:47:26 am »
    Hi boys
    I think that Steve points out a very important issue:
     NOT is not the reverse of AND so when condition is a compound evaluation of conditions we must use the CONST TRUE = -1 and FALSE = 0 (or if you prefer NOT TRUE), otherwise we must specify manually that (NOT compund condition) = 0 as inverse of compound conditions


    following the example of Steve
    Quote
    IF x AND y THEN
        do stuff
    END IF

    Now, if x = 4, and y = 2, then x AND y = 2, so you DO STUFF.

    Now let’s try the other.

    IF NOT (x AND y) THEN _CONTINUE
    do stuff...
    the good conversion ( because the condition is compound) is IF (NOT(x AND y) ) = 0 THEN  or in alternative way
    IF (NOT (x AND y)) = False THEN

    because as we know also from the wiki is that IF executes the codeBlock_IF when the conditionEvaluated is not 0
    Quote
    The conditionStatement evaluation by IF must be true (-1) or a non-zero numerical value for the THEN {code} to be executed.
    http://qb64.org/wiki/IF...THEN
    Programming isn't difficult, only it's  consuming time and coffee

    Offline Kiara87

    • Forum Regular
    • Posts: 164
      • View Profile
    Re: Basics of QB64 - Looping around
    « Reply #14 on: September 16, 2020, 03:36:00 pm »
    Computers are great at doing repetitive tasks for us. Here's how you can loop in BASIC.



    thank you  FellippeHeitor

    the great thing is that I can put the subtitles in Italian so I can understand what you say too

    I saw in your videos you are very experienced a very good programmer and thanks for sharing your experience
    se avessi solo un'ora per salvare il mondo, passerei 55 minuti per definire bene il problema e 5 a trovare la soluzione