danielmohr91 Posted September 5, 2010 Share Posted September 5, 2010 I'm terribly confused. I've got a simple "for" loop. I changed the increment to .1, and suddenly the loop never counts up to the max. For example, For $i = 0 To $i = 100 Step .1 ConsoleWrite($i & @LF) Next outputs this: 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 shouldn't it go from 0 to 100 in .1 steps. ie, after 1 is 1.1 1.2 1.3 and so on until it reaches 100? Also, it has trouble with negative numbers. ie, using -5 to 5 step 1 it will print -5 -4 -3 -2 -1 0 and stop at zero?! I'm so confused. I want to count in decimal steps from -5 to 5, but I can't do either, even separately. Am I doing something wrong, or is this simply a limitation of the language? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 5, 2010 Moderators Share Posted September 5, 2010 (edited) danielmohr91,Go and read the Help file page for For again and check the syntax. You might find that this runs as you want:For $i = 0 To 100 Step .1 ConsoleWrite($i & @LF) NextSpot the difference. M23Edit: But do not be surprised if some of the numbers are not exactly 0.1 apart. That is a limitation of floating point number representation, not an Autoit bug! Edited September 5, 2010 by Melba23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
JohnOne Posted September 5, 2010 Share Posted September 5, 2010 Something al little odd about the ouput for me22.122.222.322.422.500000000000122.600000000000122.700000000000122.800000000000122.900000000000123.000000000000123.100000000000123.200000000000123.300000000000123.400000000000123.500000000000123.600000000000123.700000000000123.800000000000123.900000000000124.0000000000001It does make it back to normal, then goes ski-wiff again. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Fubarable Posted September 5, 2010 Share Posted September 5, 2010 (edited) Something al little odd about the ouput for me....It does make it back to normal, then goes ski-wiff again.Nothing odd about this as this is simply how computers handle floating point numbers (in sum, without complete accuracy). Please have a look here for more on this subject: What Every Computer Scientist Should Know About Floating-Point ArithmeticI'm not sure how AutoIt does its for loops internally, but I know that in Java and C, if you are looping with a floating point index such as a double, your stop test should always use relational operator such as >= or <= and not just the equivalence operator, because it's all too easy for one floating point number to not be 100% equal to another even though logic tells you that they should be equal. Edited September 5, 2010 by Fubarable Link to comment Share on other sites More sharing options...
wakillon Posted September 5, 2010 Share Posted September 5, 2010 MelbaYou are right ! c'est "ballot" comme erreur ! AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts Link to comment Share on other sites More sharing options...
danielmohr91 Posted September 5, 2010 Author Share Posted September 5, 2010 danielmohr91, Go and read the Help file page for For again and check the syntax. You might find that this runs as you want: For $i = 0 To 100 Step .1 ConsoleWrite($i & @LF) Next Spot the difference. M23 Edit: But do not be surprised if some of the numbers are not exactly 0.1 apart. That is a limitation of floating point number representation, not an Autoit bug! Ha he. Thanks man. Wow, I feel like an idiot. I've been teaching myself JAVA and C++, and now coming back to AutoIt is the most unnatural thing. I keep mixing up the syntax. Things like declaring types for variables, and putting a semi-colon after every line lol. Thanks SO much for your help Link to comment Share on other sites More sharing options...
JohnOne Posted September 5, 2010 Share Posted September 5, 2010 For $i = 0 To 100 Step .1 ConsoleWrite(Round($i,1) & @LF) Next AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now