4 ms·
> for (int i =0;i<len;i++){ if(lines[i] == "a"){ i+=2; } else{ parseLine(lines[i]); } } You must be one of those managers who like to dabble in coding! I don't
by hskl 10y ago
> for (int i =0;i<len;i++){ if(lines[i] == "a"){ i+=2; } else{ parseLine(lines[i]); } }
You must be one of those managers who like to dabble in coding! I don't even know what you wanted to do. Is that C++? That part `lines[i] == "a"` is string comparison, right? And `len` is the amount of lines, right? I'll use a list instead.
I'd do it in C# with LINQ but I'm at my folks, so I only have an iPad. Here's the biggest Haskell program I ever wrote in my entire career:
dropTwoIf :: (Eq a) => a -> [a] -> [a]
dropTwoIf _ [] = []
dropTwoIf s (x:xs)
| s == x = dropTwoIf s (drop 1 xs)
| otherwise = x : dropTwoIf s xs
myList = [ "will pass", "will pass", "a", "will skip", "will pass", "a", "will skip", "a" ]
main = mapM_ print (dropTwoIf "a" myList)
Result:
"will pass"
"will pass"
"will pass"
Thanks for forcing me to actually do something bigger than Hello World of fib in this Haskell thing.
EDIT: Sure, it looks bigger than the for loop, but at least it has a name (but I'm not that good at naming) and it can be put in a library and reused. I'm pretty sure I could do MUCH better if I actually knew the standard library.
EDIT 2: Huh, figured out the type.
- dispose13432 10y ago>You must be one of those managers who like to dabble in coding! I don't even know what you wanted to do. Is that C++? That part `lines[i] == "a"` is string comparison, right? And `len` is the amount of lines, right? I'll use a list instead. It was more along the lines of pseudo-code (I couldn't be bothered to type the whole srcpy business or to look up C++ array length method).