Up until recently, have been trying to validate user input by writing lengthy if-statetments nested in while-loops. I usually have the while-loop check that the function that takes input - for instance getchar() - is not EOF and the if-statement checking whether input is of the desired data type and/or size. But then I noticed people doing something similar with infinite loops while(1) and for(;;).
While I understand that these loops are infinite because there is no condition to check against in for(;;) and because the condition is always true in while(1), I wonder if there is a more pedagogical (?) way of expressing the same thing. Like a proof of concept, or like what's going on at the electronic/logic level, if one were to draw this on a schematic with logic gates.
Or am I perhaps overthinking it and there is "simply" a signal/transistor somewhere that is always on/1/true/has the approproate votlage? Feels like "fooling" the machine by writing while(1) or for (;;) ....
Programming languages are very far removed from what's actually going on.
You could express the do forever loop as label: startofloop Workload Goto startofloop
If you want the details: you just put the instructions pointer back to the start of loop and get the stack in that state, too.
But the use of goto is generally discouraged. Please note that some programming languages allow the compiler to do anything they want if there is an infinite loop, even texting your ex. (This is for optimization reasons and not maliciousness)
save