95
u/Lost4468 Nov 21 '18
while(1)
{
try
{
if(scanner.hasNext() && !scanner.isLast())
{
int i_plus_one = scanner.getIndex() + 1;
int scannerLength = -1;
Scanner NewScanner = scanner.next();;
bool _IS_LAST = false;
for(;!_IS_LAST;)
{
if( !newScanner.hasNext() || scanner.isLast())
{
scannerLength = newScanner.getIndex();
_IS_LAST = true;
break;
}
else
//continue the loop
continue;
}
if(scannerLength <= i_plus_one)
{
//throw the custom exception for this
throw new FoundBiggest_valueexception("found end of iterator");
}
else if( i_plus_one < scannerLength) doSomething();
}
}
catch(FoundBiggest_valueexception fbve)
{
//log a message
logger.info("reached end of iterator");;
break;
}
catch (Exception e)
{
/*ignore other exceptions*/continue;
}
}39
10
u/nathancjohnson Nov 22 '18
while (1) { try { try { if (scanner.hasNext() && !scanner.isLast()) { int i_plus_one = scanner.getIndex() + 1; int scannerLength = -1; Scanner NewScanner = scanner.next();; bool _IS_LAST = false; for (; !_IS_LAST;) { if (!newScanner.hasNext() || scanner.isLast()) { scannerLength = newScanner.getIndex(); _IS_LAST = true; break; } else //continue the loop continue; } if (scannerLength <= i_plus_one) { //throw the custom exception for this throw new FoundBiggest_valueexception("found end of iterator"); } else if (i_plus_one < scannerLength) doSomething(); } } catch (FoundBiggest_valueexception fbve) { //log a message logger.info("reached end of iterator");; throw new ExitException("reached the end!"); break; } } catch (ExitException e) { System.exit(0); } catch (Exception e) { /*ignore other exceptions*/ continue; } }7
2
39
u/Miserable_Fuck Nov 21 '18
This is the story of a person writing the same piece of code as they develop degenerative brain cancer. That's a tumor explosion in the last pic.
10
7
Nov 22 '18
It's missing one thing. You're not writing the input to a plaintext file then calling the contents with a separate script.
4
6
5
u/tdammers Nov 21 '18
function go() {
if (scanner.hasNext()) {
doSomething();
go();
}
}
go();I take it your language has TCO, yes?
3
1
2
u/Xiefux Nov 22 '18
i=1;
while (i==1){
work;
}
fuckGoBack; 1
1
u/techworker123 Nov 22 '18
I'll make it easier for you. Just set a limit of scans and if the limit arrived cancel the function.
register_shutdown_function(function() {
global $documents;
if(error_get_last() === null) {
die('Scanned ' . $documents . ' documents. Thank you!');
} else {
die('Scanned ' . $documents . ' documents. Had to stop! Just run again!');
}
});
$documents = 0;
function scan($maxRuns) {
global $documents;
$scanner = new Scanner();
scan:
if($documents === $maxRuns) {
// THE TRICK!
ini_set('memory_limit', '2M');
@array_fill(0, 4*16384, chr(rand(65,90)));
}
$documents++;
if($scanner->hasNext()) {
goto scan;
}
}
scan(10); // scan ~10 documentsYou're welcome
2
22
u/TheSinfulKing Nov 22 '18
Some backstory: the last snippet was real code my TA friend saw in a 1000 level CS course, apparently the kid spent an hour on stackoverflow and was convinced that was the proper way to do it and he was so proud