Page 1 of 1

Loops

Posted: Fri Apr 20, 2007 6:55 pm
by ALAN_26
hello

I'm having a bit of a problem the loop dose not seem to work well .

example1 : loop while Variable = 10 ..............The loop ends imeditly !

example 2 : loop while varible1 = variable2 ......The loop ends imeditly !

example3 : loop while Variable < 10 .............. works fine !

example4 : loop while Variable > 10 .............. works fine !

can any one help please am i doing something wrong ?

Thanks in Advance

Regards Alan

Posted: Fri Apr 20, 2007 7:05 pm
by Chet
Testing the varible inside the loop, may work.

Posted: Fri Apr 20, 2007 7:32 pm
by ALAN_26
hello

Wath do you mean

i just made a simple program to test it loop while variable =10 and in the loop a calculation variable = varable +1 but it dose not work
The variable value is 1 and the loop ends !


This is from MM course :
The properties dialogue box shows you the options you have for controlling the loop. Next to the 'Loop while:' statement is the loop control text box. In this text box you put the loop condition: the loop will keep running until this condition is met. For example in this text box you could write:

count = 10 (Loop runs while variable count = 10) (not working)

count > 4 (Loop runs while variable count is greater than 4) (ok works)

count = preset (Loop runs while variable count is the same as variable reset) (not working)

Posted: Sat Apr 21, 2007 4:44 am
by Chet
I just looked at some code I've got and I actually test a input
varible. So it's really checking the state of a pin.

Posted: Sat Apr 21, 2007 7:12 am
by ALAN_26
Hello

I'm not tying to test an I/O pin I'm just trying to loop untill a Specified value of the variable is meet, and i just cant do that whit a loop .

I know it can easly be done with an if and goto statments but with a loop it does not work !

Posted: Mon Apr 23, 2007 9:50 am
by Benj
Hello

The while loop will only work when then condition is true.

EG while var1 = 10 will run forever while var1 is equal to 10.

if var1 starts off at 1 then the while loop will never run because var1 does not equal 10.

You can make a while loop run a set number of times by double clicking the icon and selecting the loop count option.

Posted: Mon Apr 23, 2007 9:52 am
by Steve
If you have a while loop with the condition "count = 10" at the beginning of the loop, it will only enter the loop if the "count" variable equals 10. If "count" does not equal 10 before the loop command, then the loop will never be entered.

I think the statement "the loop will keep running until this condition is met" is not right and might be causing confusion. It should probably say "the loop will keep running while this condition is true".