232showtime

For Loop Infinite

11 posts in this topic

#1 ·  Posted (edited)

Good day,

is it possible to make a For Loop infinite,

ho do i make a for loop infinite??? using the script below

For $i = 0 To 10
Msgbox(64, "Succes", $i)
Next

 

Edited by 232showtime

ill get to that... i still need to learn and understand a lot of codes graduated.gif

Correct answer, learn to walk before you take on that marathon.

Share this post


Link to post
Share on other sites



232showtime,

Use a While...WEnd loop - but you will need to have some way of exiting it at some point.

M23

1 person likes this

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Hello. As Melba says Correct way is using While. But a for can be infinite this way.

 

For $i = 0 To 1
Msgbox(64, "Succes", $i)
$i-=1
Next

Saludos

2 people like this

Share this post


Link to post
Share on other sites

@Melba23

noted...

@Danyfirex

wow this is really something. thanks for sharing.


ill get to that... i still need to learn and understand a lot of codes graduated.gif

Correct answer, learn to walk before you take on that marathon.

Share this post


Link to post
Share on other sites

BTW you can also run an unbounded loop with Do..Until


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

@jchd There's only one type of loop right?

Do
Until False

Warning: Loop will run infinitely. Add a sleep value, or some other code, within the loop to prevent cpu overheating.

Edited by czardas

Share this post


Link to post
Share on other sites

Yes and since a so-called "infinite loop" has no exit condition, all forms are equivalent: a linear code block terminated by a backward branch. Note that the term infinite has zero practical meaning in computer science, since noone can reasonably expect anything being infinite in the real world. Abstract mathematical objects actually infinite aren't defined by means of an infinite loop.

It remains that Do..Until seems to be underused in code regularly posted, compared to While..Wend, without good reason in many situations. There is no theoretic grounds to infer that more than half of useful algorithms need to check exit condition at inner code block entry (While) or exit (Until).

1 person likes this

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

one more way is setting Step = 0 (just for fun)

Local $end

For $i = 0 To 0 Step 0
    ConsoleWrite($i & @CRLF)
    ; .....
    $end += 1
    If $end = 10 Then $i = 1 ; to exit set $i > of the To value
Next

 

1 person likes this

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites
1 hour ago, jchd said:

It remains that Do..Until seems to be underused in code regularly posted

I agree with you.

I was inferring that all loops in programming do pretty much the same thing: in so much as they repeat until a condition is met, or not. The comment was a follow up on your earlier post and I thought it worth a mention. Implementation may vary of course. I imagine loops which increment an iteration count ought theoretically be slower. It stands to reason, although in the real world things might not be so straight forward.

Share this post


Link to post
Share on other sites

My remark was more towards whether preconditions or postconditions dominate in loop constructs. Given a significant sample of distinct general-purpose algorithms, the ratio is close to 1/2, while in common code people tend to code While <cond> ... Wend with <cond> always true at entry.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

I meant to answer, but fell asleep. I was thinking it might be a good idea to get rid of the condition altogether and just simply have the loop. Terms like 'While', 'For' and 'Until' are rather specific. I'm speaking more generally in terms of language design - not necessarily AutoIt.

Edited by czardas

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now

  • Similar Content

    • Eli_jahbot
      By Eli_jahbot
      My esteemed Autoits I need your help once again.
      I'm trying to figure out how to create a loop that gets 1 value from an array and repeats until each value from the array has been used. I have never used arrays before and I know once I learn more things should get easier for me. 
      Here is what Im trying to do:
      -Have an array of values that determine what application i log into. ex: app1, app2, app3, app4 etc.
      -Have a loop that repeats a process sequentially using each value in the array to finish the process for each app1, app2, app 3 and so forth. I have 30 apps that I need to update on a regular basis and getting this sorted out is what I perceive to be the best way to do it.
      Here is my feeble attempt that obviously fails:
      #include <msgboxconstants.au3>
      #include <Constants.au3>
      #include <array.au3>
      Login()
      Func Login()
          local $array[30] = ["10", "11", "12",etc etc]
          ;;Local $site = InputBox("ERx Site","What site do you want to login as?","","")
          Local $userid = InputBox("ERx Login", "What is your username?", "", "")
          Local $Passwd = InputBox("Security Check", "Enter your UAT password.", "", "*")
      for $1 = 1 to 30(I need to do the same steps in 30 different apps)
      run("Z:launch.exe")
      WinWaitActive("Input")
      Send (Sequential ARRAY VALUE HERE)
      Send("{ENTER}")
      WinWaitActive("window")
      Send($userid)
      Send("{TAB}")
      send($Passwd)
      Send("{ENTER}")
      WinWaitActive("[CLASS:SunAwtDialog]")
      Sleep(500)
      WinClose("Home Page")
      Next
      EndFunc
       
      your help is greatly appreciated.
      Thanks for your time
    • Szmycu
      By Szmycu
      Hello i Have HP Bar in my game and it has 170px of width and then im gonna find start of this by mouse pos then i got $hpStart[0] = 661  $hpStart[1] = 230 ,  $hpEnd[0] = 839
      And there is from $hpStart[0] = 661 the same color - 0xCB423B but depends of my points of hp for example on pixel  $hpStart[0] = 745 would be another color not  0xCB423B and then i will know my my character got 50% of health points.
       
      I encountered problem here - for loop still looping to 839 and not founding this change in color for example on pixel $hpStart[0] = 745
      I would know actual $i counter and $hpEnd[0] then only i can calculate current health percent value 
       
      Please help me how to achieve that! Thanks for any help
       
      Func MouseCord() $MousePos = MouseGetPos() global $hpStart = $MousePos global $hpEnd = $hpStart $hpEnd[0] = $hpEnd[0] + 170 For $i = $hpStart[0] To $hpEnd[0] ; Looping from 661 to 839 $pixel = PixelGetColor($i,$hpStart[1]) If $pixel <> 0xCB423B Then $hpNowPer = ( $hpEnd[0] - $i ) / 170 $hpPoOdjeciu = 1 - $hpNowPer $hpNowPercent = Round($hpPoOdjeciu,2) ExitLoop ; - that not working EndIf Next EndFunc  
       
    • cherrylatte
      By cherrylatte
      Hi guys 
      I am trying to execute each version of a browser (first for loop) and get a version of each of the file database by using SQLite tool. (second loop) 
      The first for loop seems to work fine. But when it goes into a second loop, the second for loop seems to stop after like 1~2 times of looping.
      I could not find the reason for it.  
      If I separate those loops into each au3 files,,then it seems to work fine...I'll show you guys the code..I'd appreciate it if anybody finds a solution
      #include <Array.au3> #include <File.au3> ;#include <MsgBoxConstants.au3> Opt("WinTitleMatchMode", 2) Global $result_file1 = "C:\Users\hello\Desktop\result.txt" Local $sFilePath1 = "C:\test" Local $sFilePath2 = "C:\test\User Data" Local $aFileList = _FileListToArray($sFilePath1 , "test*", Default, True) ;get the whole path of files starting with 'test' under C;test  and put it in array Local $aSaltList = _FileListToArrayRec($sFilePath2,  "file db",1, -2 , 1, 2) ; get the whole path of files named ' file db' under 2 depth of userdata  folder For $i=1 to UBound($aFileList)-1    Sleep(3000)    ShellExecute($aFileList[$i])    Local $hWnd = WinWait("chrome"," ",10)    WinActivate($hWnd)    Sleep(6500)    WinClose($hWnd)    Sleep(100)    ProcessClose ("chrome.exe")    Sleep(4000) Next For $j=2 to UBound($aSaltList)-1    Sleep(3000)    ShellExecute($aSaltList[$j]) ;;PROBLEM    Sleep(2000)    ;sqlite    Open()    Sleep(3000)   ;run sql    RunSql() Next Func Open() ;open sqlitespy Sleep(3000) Send("s") Sleep(1500) Send("{ENTER}") EndFunc Func RunSql() ;run a sql sentence and save the result in a result.txt file    ControlClick("[CLASS:TfrmMain]","","[CLASS:TDISynEdit]")    Send("select * from version {F9}")    ControlClick("[CLASS:TfrmMain]","","[CLASS:TMemo]","left",2)    Sleep(1500)    Send("^c")    Local $string1 = ClipGet()    FileWrite($result_file1, $aSaltList[$j])    FileWrite($result_file1, "    ")    FileWriteLine($result_file1, $string1)    ProcessClose ("SQLiteSpy.exe") EndFunc  
    • Relive
      By Relive
      An IE link collection $oLinks is being looped by a $oLink with a for-in loop. An if statement is used such that when the $oLink.href matches a string reg. exp., it will do a set of statements. The set of statements is this:

      $a = 1 do $matchpic = StringRegExp($oLink + $a.href, '(http://t2.imgchili.com/)(\d+)(\/)(\d+)(_)') $a += 1 until $matchpic = 1 But the error is that $a is not an object variable.

      After a match has been found, this $oLink is _paused_ at the current position inside this collection (I believe). How do I loop at the current $oLink?
    • BrewManNH
      By BrewManNH
      Here's a piece of code:

      Global $Array[5] = ["AA", "BB", "CC", "DD", "EE"] For $I = 2 To $Array ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $I = ' & $I & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console Next The results for this piece of code are very strange:

      Is this a bug with the For code, in that it's acting somewhat like a For/Next loop, and somewhat like a For/In/Next loop? By the way, it doesn't matter what the first number in the loop is, I used 2 as an example, it will always output the same. It takes the number you started the loop at, and then the variable will hold the contents of the second through the last array elements.
      On a 2D array, it still doesn't work as expected, but it works differently than how I'd expect it to.


      Global $Array[5][2] = [["AA", "1"], ["BB", 2], ["CC", 3], ["DD", 4],["EE", 5]] For $I = 10 To $Array ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $I = ' & $I & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console Next This outputs:

      Which is 5 instances of $ being 10, which seems to be a quick way of looping through an array if you don't need to access the contents of the array.