Do/Loop While ?

Started by Zlatko Vid, December 01, 2024, 06:19:34 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Zlatko Vid

Hello Charles..others

does o2 support

Do
...
...
...
Loop While expr

?
I mean i always use Do / End Do
or
While / Wend

or can i replace

Do /Loop While with...

Do loop ? and how  ?

Charles Pegge

Yes,

uses console
int i
do
  i++
  print i cr
'OPTIONS:
'loop while i<10
'loop when i<10
'loop until i>9
'loop if i<10
loop if not i>9
wait

Similar option exist for exit and continue

Zlatko Vid

or can i use just this :

int i
do
  i++
  print i cr
   if i=10 : exit do : end if
end do

Pierre Bellisle

#3
Hi Aurel,
While waiting for Charles answer,
on my side, one thing I like is to be able to
put dual conditions, one in the do line and also one in the loop line.
This make the code more compact and often easier to read.

// KickSwitch -64 -r
// KickEnd

include once "console.inc"
include once "windows\msvcrt.inc"

%BCRYPT_USE_SYSTEM_PREFERRED_RNG = 2
! BCryptGenRandom lib "bcrypt.dll"(sys hAlgorithm, sys pbBuffer, dword cbBuffer, dword dwFlags) as long
'_____________________________________________________________________________

SetConsoleTitle("loop")
long index = 0
byte RandomByte

printl
printl "do until RandomByte > 245"

do until RandomByte > 245
  BCryptGenRandom(0, @RandomByte, 1, %BCRYPT_USE_SYSTEM_PREFERRED_RNG)
  printl "  index = " index ", RandomByte = " RandomByte
  index ++
loop while index <= 5

printl "loop while index <= 5"
printl
printl : printl "Press a key or click to end"
waitkey

end
'_____________________________________________________________________________
'

Charles Pegge

The compiler has to break all these looping expressions into a simple  do .. loop  containing one or more conditionals, containing an exit/continue instruction.

They are all luxury items for hand-coding. If you use an AI agent to produce the code, you might find it simpler to eliminate all while and for constructs.

Zlatko Vid

Hi Pierre....Charles

my intention is to avoid Loop While in this loop construct
because really i don't use in any of my programs Do/Loop While
i prefer Do/End Do and While/Wend

in first place i was asking because this is used in many C or Java programs
and i am doing some translation