Jump to content

The script does not exit the FOR…LOOP


XavS
 Share

Recommended Posts

II have two For Loop operations ; the first works as expected ; but the second one does not: It looks as if the second operation

Cannot exit the loop .

The end game is to  be able to use the loop results for further operation.

 

 I hope the below two examples will provide more clarification of my problem.

 

Example 1:This works fine I could display the result of the loop out site the loop

#include <Array.au3>

Global $astring = ["aaa_string","bbb_string","ccc_string","ddd_string","eee_string","fff_string"]
For $i = 0 To UBound($astring)-1 Step 1
    If StringInStr($astring[$i],"ccc",1)<>0 Then
        $astring[$i] = StringReplace($astring[$i],"ccc","XXX_Wedge_")
        _ArrayDisplay($astring, "Ex:1Inner check")
    EndIf
Next
_ArrayDisplay($astring, "Ex:1 Outer check")

 

Example 2:The loop result cannot  be display outside the loop.

#include <Array.au3>

Global $astring = ["aaa_string","bbb_string","ccc_string","ddd_string","eee_string","fff_string"]
For $i = 0 To UBound($astring)-1 Step 1
    If StringInStr($astring[$i],"ccc",1)<>0 Then
        _ArrayDelete($astring,$i)
        _ArrayDisplay($astring, "Ex:2 Inner check")
    EndIf
Next
_ArrayDisplay($astring, "Ex:2 Outer check")

What I can do to  be able to  have the example 2 loop result to be displayed outside the loop (_ArrayDisplay($astring, "Ex:2 Outer check"))

Your help and assistance as always  been very much appreciated .

 

Link to comment
Share on other sites

Because you're deleting array elements you're getting an errors when trying to access missing subscripts . You have to process the loop backwards

#include <Array.au3>

Global $astring = ["aaa_string","bbb_string","ccc_string","ddd_string","eee_string","fff_string"]

For $i = UBound($astring)-1 To 0 Step -1
    If StringInStr($astring[$i],"ccc",1)<>0 Then
        _ArrayDelete($astring,$i)
        _ArrayDisplay($astring, "Ex:2 Inner check")
    EndIf
Next

_ArrayDisplay($astring, "Ex:2 Outer check")

 

Link to comment
Share on other sites

Magic benners ... thank you so very much for your swift assistance in resolving my issue ....

It's there any book/links you can advise for me to understand the "mechanics" of loops ? I'm a Newbie in programming/Scripting and I was told that Autoit was a better place to start; hence my eagerness to know more about this tool which has so far been very very useful for me... Any pointers would very much appreciated .

Cheers 

Link to comment
Share on other sites

First port of call would be the help file. There are loads of examples about the functions and info on what to expect when errors occur and return values. Next would be the wiki Normally a google search including "AutoIt and whatever issue you might have" throw up enough results to resolve the problem or lead you in the right direction.

If you have installed the full Scite package, the output window show issues\problems that have occured with running script. You can then google these messages and get help with the items. Odds are, they have been encountered before.

Looking at what other people have posted on the forum, such as in the example scripts forum, or replies to other posts, give you new ideas on how to do things. These can be bookmarked or saved as snippets as you never know how far you'll end up going with this language.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...