Jump to content

Loop not exiting.


Go to solution Solved by water,

Recommended Posts

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

  • Solution
Posted (edited)

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:

  Reveal hidden contents

 

Posted

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:

  Reveal hidden contents

 

Posted
  On 9/20/2021 at 6:42 PM, water said:

I would vote for multiple solutions.

Expand  

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…

Expand  

 

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

Posted

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:

  Reveal hidden contents

 

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
  • Recently Browsing   0 members

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