No difference, if "quantity" is already less than the loop's start counter, then the loop will never be executed, but is skipped immediatly. The program proceeds with the line following the NEXT statement. However if "quantity" is greater than the start counter, then you only would add another (useless) check with the IF...THEN block, hence you are slower with your second example.Okay thanks, good to know.
FOR ...NEXT is slow loop structure, WHILE ...WEND or DO ...LOOP are faster, of course you have to code exit to avoid infinite loop.So I should never use FOR...NEXT loops? Just DO...LOOPs with an counter as exit condition? Do you know why DO...LOOPs are faster?
S_1:;
fornext_value2= 0 ;
fornext_finalvalue2= 100 ;
fornext_step2= 1 ;
if (fornext_step2<0) fornext_step_negative2=1; else fornext_step_negative2=0;
if (new_error) goto fornext_error2;
goto fornext_entrylabel2;
while(1){
fornext_value2=fornext_step2+(*__SINGLE_I);
fornext_entrylabel2:
*__SINGLE_I=fornext_value2;
if (fornext_step_negative2){
if (fornext_value2<fornext_finalvalue2) break;
}else{
if (fornext_value2>fornext_finalvalue2) break;
}
fornext_error2:;
if(qbevent){evnt(1);if(r)goto S_1;}
fornext_continue_1:;
}
fornext_exit_1:;
do{
*__SINGLE_I= 0 ;
if(!qbevent)break;evnt(1);}while(r);
S_2:;
do{
if(qbevent){evnt(2);if(r)goto S_2;}
do{
*__SINGLE_I=*__SINGLE_I+ 1 ;
if(!qbevent)break;evnt(3);}while(r);
S_4:;
dl_continue_1:;
}while((!(-(*__SINGLE_I> 100 )))&&(!new_error));
dl_exit_1:;
if(qbevent){evnt(4);if(r)goto S_4;}
*__SINGLE_I= 0 ;
do{
*__SINGLE_I=*__SINGLE_I+ 1 ;
dl_continue_1:;
}while((!(-(*__SINGLE_I> 100 )))&&(!new_error));
dl_exit_1:;
fornext_value2= 0 ;
fornext_finalvalue2= 100 ;
fornext_step2= 1 ;
if (fornext_step2<0) fornext_step_negative2=1; else fornext_step_negative2=0;
if (new_error) goto fornext_error2;
goto fornext_entrylabel2;
while(1){
fornext_value2=fornext_step2+(*__SINGLE_I);
fornext_entrylabel2:
*__SINGLE_I=fornext_value2;
if (fornext_step_negative2){
if (fornext_value2<fornext_finalvalue2) break;
}else{
if (fornext_value2>fornext_finalvalue2) break;
}
fornext_error2:;
fornext_continue_1:;
}
fornext_exit_1:;
I'm still wondering, why the FOR...NEXT loop has such a bulky (goto label) implementation from QB64 -> C++ level. Wouldn't it be better simply translated into a C++ "for" loop?
fornext_value2=fornext_step2+(*__SINGLE_I);
fornext_entrylabel2:
*__SINGLE_I=fornext_value2;
Hi McFreyer,Windows 10 Laptop, Intel Celeron 2.16GHz, 4GB RAM
:D I have to ask, what OS and computer are you using? What version of QB64?
Let's take a moment to look at how our QB64 code translates into C-code.Thanks for the insight!!!!
Windows 10 Laptop, Intel Celeron 2.16GHz, 4GB RAM
QB64 v0.954
I will download the latest version now...
Thanks for the insight!!!!
EDIT:
the 1.3 version (64 bit) was faster, from 10.6 sec (FOR...NEXT) till 11.9 sec (DO...LOOP)
the FOR...NEXT loop was still the fastest...
Can Celeron processor support Windows 10?
For processing, Windows 10 requires a CPU with a minimum speed of 1GHz. This is a very low bar to clear, as even Intel's low-powered Atom and Celeron processors have been above the 1GHz mark for several years. ... You'll also want to look up whether or not your processor supports a 64-bit operating system.Oct 17, 2017
Let's take a moment to look at how our QB64 code translates into C-code.
First, let's start with a simple FOR...NEXT loop:
...
Out of curiosity, could you guys who are seeing the faster FOR loops add the $CHECKING:OFF command to Bplus's code and then run it. I'm curious how much of a delay the internal error checking processes are making on the code.
Tr this, and see how it performs for you folks:Code: QB64: [Select]
running on my desktop, also VISTA get more consistant times, but GOTO becomes the fastest and While\Wend the slowest!!
From the numbers you posted, don’t you mean FOR..NEXT was the slowest?
... s(2.58), fallowed by WHILE\WEND(2.91), th ...been looking up info on fallow deer too much! :D
I was curios about, because you mentioned and option in "Google Translate", but maybe i got that wrong.