frankcollins3 / fcc-mcsft-cSharp

FreeCodeCamp & Microsoft C# course:
1 stars 0 forks source link

goto cb() positioning [11:34am] #35

Closed frankcollins3 closed 1 year ago

frankcollins3 commented 1 year ago

attempting to do: search function -> sampleDataLoop() nested loop. -> check innerloop string arrays for searchTerm equality -> if (match) => return index[name]; if (!match) => create callback function for goto Screen Shot 2023-09-10 at 11 36 30 PM

heres the if block that matches. the else block is encountered upon search criteria meeting none of the nested loop contents Screen Shot 2023-09-10 at 11 36 44 PM

in seeing that such a goto function: that takes string param, determining different codeblocks with .WriteLine() messages confirming yes or no to {goto()}

if this is to be used over and over, I foresee a problem with this function: if its a callback function, then it will be above the {goto} keywords: error:

proposed approach: in Arduino, a callback function can be used at the top level or all the way on the bottom. Not sure if that will work.

possible improvements:

frankcollins3 commented 1 year ago

intellisense? the auto-infer is showing test() above it's declaration. Screen Shot 2023-09-10 at 11 43 22 PM [11:43pm]

frankcollins3 commented 1 year ago

kind of surprised that works. it doesn't matter whether the function is above or below it's invocation. [11:45pm]

frankcollins3 commented 1 year ago

interesting problem. searchTraits() is a function within searchDogs() searchDogs() has 2 {goto} statements. even scoped within the outer searchDogs() statement, the inner function does not have access to the other statements.

Screen Shot 2023-09-10 at 11 57 42 PM Screen Shot 2023-09-10 at 11 58 29 PM

frankcollins3 commented 1 year ago

no callback function for goto but did learn that the func() can be at bottom of app so it has access to goto statements. It just didn't work in this case because of callback scope which would probably apply to alot of situations.. limiting the use of such a catch all goto() function that uses params to display conditional code block. [12:19am]