I’ve been wondering about alternative ways to write control structures like you can write your own language constructs in Forth.
One that you learn early on for if statements is a replacement for this:
if ( x ) {
// true
} else {
// false
}
with this (sometimes this is more readable compared to lots of brackets):
x ? true : false
It got me thinking. Can we replace anything else incase it’s more readable.
So those are the ones I can think of off the top of my head for the if statement and doing comparisons.
So I’m wondering what about how to replace looping constructs like for, while, etc.
How would you replace a while loop for example (without using a for loop). It’s probable that it can’t be done in these languages?
while (a < b) {
}
Loops can be replaced by recursion.