Jump to content

Loop not exiting.


 Share

Go to solution Solved by water,

Recommended Posts

WinActivate ("LMS — Mozilla Firefox")

 Global $j = 0, $k = 0
Do
   MouseClick("left", 415, 205, 1)
   Sleep(2000)
   Do
      MouseClick("left", 1271, 858, 1)
      Sleep(10000)
      $j = $j + 1
   Until $j = 2 ; Increase the value of $j until it equals the value of 2.
   $k = $k + 1
Until $k = 2 ; Increase the value of $k until it equals the value of 2.
Exit

The problem is that the second loop keeps on running.

I'm obviously missing something simple.

I'm new to this. Please help.

Link to comment
Share on other sites

  • Solution

Welcome to AutoIt and the forum!

You have to reset $j when you start the inner loop again:

WinActivate ("LMS — Mozilla Firefox")

Global $j = 0, $k = 0
Do
   MouseClick("left", 415, 205, 1)
   Sleep(2000)
   $j = 0
   Do
      MouseClick("left", 1271, 858, 1)
      Sleep(10000)
      $j = $j + 1
   Until $j = 2 ; Increase the value of $j until it equals the value of 2.
   $k = $k + 1
Until $k = 2 ; Increase the value of $k until it equals the value of 2.
Exit

 

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

@wateris correct.

Why not just:

WinActivate ("LMS — Mozilla Firefox")

For $k = 0 To 1 
   MouseClick("left", 415, 205, 1)
   Sleep(2000)
   For $j = 0 To 1
      MouseClick("left", 1271, 858, 1)
      Sleep(10000)    
   Next
Next
Exit

 

Edited by JockoDundee

Code hard, but don’t hard code...

Link to comment
Share on other sites

32 minutes ago, Bekaarfaltu said:

@JockoDundee Your solution is much cleaner and simpler. For...Next loops seem better. Thanks!

Unfortunately, it seems not possible to mark more than one post as "Solution" :(.

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

I would vote for multiple solutions. There is more than one way to skin a cat :)
As a user I would like to select the most elegant/efficient code from a bunch of "solutions".

Just my 2 cents worth ;)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

2 hours ago, water said:

I would vote for multiple solutions.

I would agree.

In this case though, I’m not worthy, since at the very moment that water posted $j = 0, my draft response showed something like:

Quote

The program should exit in 44 seconds…

 

Code hard, but don’t hard code...

Link to comment
Share on other sites

Your updated version not only fixed the problem but is much cleaner and elegant. So the OP can learn how good code looks like in addition.
Every post that solves the OPs problem should be a candidate to be marked by the OP as "Solution".

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

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...