c - replace if/else with while/if statement -
c - replace if/else with while/if statement -
is possible replace if/else statement while , if statement(s) (say, we're working in c)? if it's possible, can please share example. so, have
if (cond1) exec1 else exec2 and want rid of if/else , utilize if/while constructs.
is plenty turing finish language have while/if statements (for command flow)?
how if/else constructs?
(this not homework, out of curiosity)
for general replacement of if() ... else ... construct, can cache result of condition:
int status = cond1; if(condition) exec1; if(!condition) exec2; that way avoid issues sideeffects in cond1 , exec1.
concerning question turing completeness: paul griffiths notes, if() , goto sufficient. however, if() , recursion. can replace while(cond1) exec1; loop self recursive function:
void loopy(/*whatever state loop touches*/) { if(cond1) { exec1; loopy(/*pass on current state*/); } } this fact heavily abused in functional languages lisp , scheme. when larn programming in these languages, taught write recursions in such way (tail recursion) compiler can figure out intended write loop , optimize accordingly...
c if-statement while-loop
Comments
Post a Comment