QB64.org Forum

Active Forums => QB64 Discussion => Topic started by: FellippeHeitor on September 06, 2020, 10:17:50 am

Title: Basics of QB64 - Looping around
Post by: FellippeHeitor 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.

Title: Re: Basics of QB64 - Looping around
Post by: bplus on September 06, 2020, 10:44:30 am
Oh wow, didn't know QB64 has _CONTINUE and can use it in any loop structure.
Title: Re: Basics of QB64 - Looping around
Post by: FellippeHeitor 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.
Title: Re: Basics of QB64 - Looping around
Post by: Dav 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
Title: Re: Basics of QB64 - Looping around
Post by: FellippeHeitor 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!
Title: Re: Basics of QB64 - Looping around
Post by: wiggins 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!!!
Title: Re: Basics of QB64 - Looping around
Post by: FellippeHeitor 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.
Title: Re: Basics of QB64 - Looping around
Post by: JohnUKresults on September 08, 2020, 07:20:04 am
Thanks Fellippe. Good to know about _Continue! Could prove useful.
Title: Re: Basics of QB64 - Looping around
Post by: OldMoses 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.
Title: Re: Basics of QB64 - Looping around
Post by: TempodiBasic 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.
Title: Re: Basics of QB64 - Looping around
Post by: TempodiBasic on September 14, 2020, 04:51:45 pm
_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]
Title: Re: Basics of QB64 - Looping around
Post by: OldMoses 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.
Title: Re: Basics of QB64 - Looping around
Post by: SMcNeill 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)

Title: Re: Basics of QB64 - Looping around
Post by: TempodiBasic 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 (http://qb64.org/wiki/IF...THEN)
Title: Re: Basics of QB64 - Looping around
Post by: Kiara87 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
Title: Re: Basics of QB64 - Looping around
Post by: FellippeHeitor on September 16, 2020, 05:39:51 pm
Thanks, Kiara87!

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

Hmmm, interesting! I'll check out how it goes in Italian.