Page 1 of 1 1
Topic Options
#143762 - 2005-07-18 09:02 PM A way to continue a loop on a condition?
thepip3r Offline
Hey THIS is FUN
*****

Registered: 2005-03-02
Posts: 350
If I'm running a loop and I have a conditional that runs in the start of the loop and if the conditional returns true to have the loop continue without doing anything else?? Is there a way to do this in KiX?? like a continue; function or something?

Edited by thepip3r (2005-07-18 09:29 PM)

Top
#143763 - 2005-07-18 09:16 PM Re: A way to continue a loop on a condition?
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
no sprechen gibber...

more detail please.

Concerning loops, have you looked at do/while and loop/until?
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#143764 - 2005-07-18 09:22 PM Re: A way to continue a loop on a condition?
thepip3r Offline
Hey THIS is FUN
*****

Registered: 2005-03-02
Posts: 350
Code:
$x = 1
while $x < 5 AND $x > 3
if $x = 4
continue()
endif
loop




Edited by thepip3r (2005-07-18 09:23 PM)

Top
#143765 - 2005-07-18 09:45 PM Re: A way to continue a loop on a condition?
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
nope. just have to write the functionality yourself. just because the keyword doesn't exist doesn't mean you can't tweak your loop to work like you want it to.

And for those that don't understand the question, check out continue keyword in c#
C# Tutorial


Edited by maciep (2005-07-18 09:50 PM)

Top
#143766 - 2005-07-18 09:50 PM Re: A way to continue a loop on a condition?
thepip3r Offline
Hey THIS is FUN
*****

Registered: 2005-03-02
Posts: 350
yeah, this is how i ended up making it work for those of you who are looking for this function in the future. it's more logic than anything but... all you have to do is run the loop, run the conditional, and only increment the loop if the conditional returns what you want it to. here's my test script i'm working on for random password generation...

Code:
Break ON
$ = SetOption("WrapAtEOL","ON")
$ = SetOption("ASCII","On")

$PassLength = 10
$LowChar = 33
$HighChar = 126

$RandomNumSeed = SRnd(@MSECS)

While $x <= $PassLength
$num = Rnd(126)
if $num >= $LowChar AND $num <= $HighChar
$newNum = CHR($num)
$pw = $pw+$newNum
if $x = $PassLength
? $pw
endif
$x = $x + 1
endif
Loop



thanx for the help guys...


Edited by thepip3r (2005-07-18 09:51 PM)

Top
#143767 - 2005-07-18 09:56 PM Re: A way to continue a loop on a condition?
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
what about just

$num = rnd(93) + 33

that should give you a random number in the appropriate range, right?

Top
#143768 - 2005-07-18 10:05 PM Re: A way to continue a loop on a condition?
thepip3r Offline
Hey THIS is FUN
*****

Registered: 2005-03-02
Posts: 350
yeah that worked great maciep. thanx for the suggestion... here is my modified code:

Code:
function genWinCompliantPassword($length) 
$PassLength = $length
$LowChar = 33
$HighChar = 126

$RandomNumSeed = SRnd(@MSECS)

While $x <= $PassLength
$num = Rnd(93) + 33
$newNum = CHR($num)
$pw = $pw+$newNum
if $x = $PassLength
? $pw
endif
$x = $x + 1
Loop

Return $pw
EndFunction


Top
#143769 - 2005-07-18 10:18 PM Re: A way to continue a loop on a condition?
thepip3r Offline
Hey THIS is FUN
*****

Registered: 2005-03-02
Posts: 350
crap, the only reason my pw is showing up is because i'm echoing it in my function. how do i get the function to return the variable $pw if my current method is not working???

Code:
function genWinCompliantPassword($length) 
$PassLength = $length
$RandomNumSeed = SRnd(@MSECS)

While $x <= $PassLength
$num = Rnd(93) + 33
$newNum = CHR($num)
$pw = $pw+$newNum
; if $x = $PassLength
; ? $pw
; endif
$x = $x + 1
Loop

Return $pw
EndFunction


Top
#143770 - 2005-07-18 10:20 PM Re: A way to continue a loop on a condition?
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Replace the line:
Return $pw

with:
$genWinCompliantPassword = $pw
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#143771 - 2005-07-18 10:24 PM Re: A way to continue a loop on a condition?
thepip3r Offline
Hey THIS is FUN
*****

Registered: 2005-03-02
Posts: 350
Thanx Les, that worked great.
Top
#143772 - 2005-07-19 05:06 AM Re: A way to continue a loop on a condition?
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
And see the UDF Forum on how to write a UDF.
_________________________
There are two types of vessels, submarines and targets.

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 1198 anonymous users online.
Newest Members
M_Moore, BeeEm, min_seow, Audio, Hoschi
17883 Registered Users

Generated in 0.098 seconds in which 0.05 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org