lsakizada Posted August 14, 2013 Share Posted August 14, 2013 I need to create a function that do infinite loop and the output is 4,5,4,5,4,5 What function to replace the ? Sign in order to accomplish it? Func () $x=4 While(true) $x=? Debugoutput(x & ',') Wend Endfunc Example: If x=4 then the output should be; 4,5,4,5,4,5, Be Green Now or Never (BGNN)! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 14, 2013 Moderators Share Posted August 14, 2013 lsakizada,I would do it using Mod like this: HotKeySet("{ESC}", "On_Exit") $i = 1 While 1 ; Toggle $i between 0 and 1 $i = Mod($i + 1, 2) ; Add 4 ConsoleWrite(4 + $i & @CRLF) ; Just to see the result Sleep(250) WEnd Func On_Exit() Exit EndFuncM23 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...
lsakizada Posted August 14, 2013 Author Share Posted August 14, 2013 Hi melba32, nice to get response from you Thanks for correcting the syntax, i am on iphone. It is almost ok, i must need to replace the '?' Sign with a proper function in order to print the desired output. Btw, it is a question that i have being asked today in my job interview. Be Green Now or Never (BGNN)! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 14, 2013 Moderators Share Posted August 14, 2013 lsakizada,Then perhaps this:HotKeySet("{ESC}", "On_Exit") $i = 4 While 1 ; Toggle $i between 4 and 5 $i = 4 + Mod(($i - 4) + 1, 2) ConsoleWrite($i & ",") ; Just to see the result Sleep(250) WEnd Func On_Exit() Exit EndFuncGood luck with the interview. M23 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...
lsakizada Posted August 14, 2013 Author Share Posted August 14, 2013 Hi melba, this solution works but not for ANY $i variable, Which mean the digit 4 should not be used in the function. Yep, I am still need to supply the complete solution in order to put bread on my table. Be Green Now or Never (BGNN)! Link to comment Share on other sites More sharing options...
kylomas Posted August 14, 2013 Share Posted August 14, 2013 Isakizada, Maybe somethiing as simple as this HotKeySet("{ESC}", "On_Exit") $i = 6 While 1 ConsoleWrite($i & ',' & $i+1 & ',') Sleep(250) WEnd Func On_Exit() ConsoleWrite(@LF) Exit EndFunc Good Luck with the $$$$$ kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 14, 2013 Moderators Share Posted August 14, 2013 (edited) lsakizada,How about you tell me ALL the constraints on the solution before I produce any more new code - I really dislike having the goalposts moved after every solution I post. For example, are we limited to just one line or can I call a function? M23 Edited August 14, 2013 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...
lsakizada Posted August 14, 2013 Author Share Posted August 14, 2013 Kylomas, it must be with same format as described in the first post on this thread. Be Green Now or Never (BGNN)! Link to comment Share on other sites More sharing options...
lsakizada Posted August 14, 2013 Author Share Posted August 14, 2013 Melba, Well, as I just told to kylomas, the interviewer asked to replace only the '?' Sign with proper function. Beside of that, that's should works for any number that assigned to the first variable before entering the infinity loop. Yours solution is Ok, but I am not sure if it will works if we will replace the digit 4 with the variable $i. I can not test it since i am on my iphone. Thanks for the help! Be Green Now or Never (BGNN)! Link to comment Share on other sites More sharing options...
kylomas Posted August 14, 2013 Share Posted August 14, 2013 Is the interviewer asking for an AutoIT specific solution? If so, "func ()" is not valid AutoIT syntax. Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 14, 2013 Moderators Share Posted August 14, 2013 lsakizada,If we can use a function the solution is very simple:HotKeySet("{ESC}", "On_Exit") $i = 4 While 1 ; Toggle $i between 4 and 5 $i = _Func($i) ConsoleWrite($i & ",") ; Just to see the result Sleep(250) WEnd Func _Func($iVar) ; Set a static variable to store the first value of the variable received by the function Static $iBase = 0 If $iBase = 0 Then $iBase = $iVar ; And run the one-liner we had before Return $iBase + Mod(($iVar - $iBase) + 1, 2) EndFunc Func On_Exit() Exit EndFuncHow about that? M23 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...
DW1 Posted August 14, 2013 Share Posted August 14, 2013 (edited) Test() Func Test() $x = 8 While (True) $x = $x + Cos($x * 3.14159265358979) ConsoleWrite($x & ',') Sleep(10) WEnd EndFunc ;==>Test Tossed the sleep in there just to not kill the CPU Edited August 14, 2013 by danwilli AutoIt3 Online Help Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 14, 2013 Moderators Share Posted August 14, 2013 danwilli, M23 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...
lsakizada Posted August 14, 2013 Author Share Posted August 14, 2013 (edited) Having fun here!!! Greetings! Edited August 14, 2013 by lsakizada Be Green Now or Never (BGNN)! 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