Sign in to follow this  
Followers 0
ratacat

help make some basic loops

3 posts in this topic

I seem to be having problems putting loops in my programs.

If anyone could show just a really small tiny prog for each loop that demonstrates it's usage, I'd greatly appreciate the help.

I could be wrong, but I was under the impression that these were the following loops.

do

until

while

wend

for

next

Share this post


Link to post
Share on other sites



well yes, but you need conditions.

$myVar = 1

While $myVar = 1

$myVar = 0

WEnd

That loop wont last very long, but you can see how to put in a conditional statement

Share this post


Link to post
Share on other sites

Not the best examples but should help. I wanted to show all the loops, but maybe a better first example would be:

$rand = Random(1, 10, 1) ;integer flag

$numTries = 1

$guess = InputBox("Enter guess", "I'm thinking of a number between 1 and 10... What's your guess?")

While $guess <> $rand

$guess = InputBox("Enter guess", "Wrong! Guess again:")

$numTries = $numTries + 1

WEnd

MsgBox(4096,"Congrats", "You guessed the number in " & $numTries & " tries.")

$rand = Random(1, 10, 1);integer flag
$numTries = 0
Do
    $guess = InputBox("Enter guess", "I'm thinking of a number between 1 and 10...  What's your guess?")
    $numTries = $numTries + 1
Until $guess = $rand
MsgBox(4096,"Example 1 of 3", "You guessed the number in " & $numTries & " tries.")

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Global $CONTINUE = 1
HotKeySet("^+q", "Quit")
Func Quit()
    $CONTINUE = 0
EndFunc
SplashTextOn("Example 2 of 3", "This is an infinite Loop... Press Ctrl+Shift+Q to terminate.")
While $CONTINUE
    sleep(100)
WEnd
SplashOff()

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

$sum = 0
For $i = 1 to 100
    $sum = $sum + $i
Next
MsgBox(4096,"Example 3 of 3", "The sum of the first 100 numbers is " & $sum)

Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!

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
Sign in to follow this  
Followers 0