c++ - Does a conditional statement stop executing if something within the statement causes that conditional to no longer be true/false? -
the following c++ code, important emphasize!
for example, mean is, have:
bool = true; if(this) { = false; //other code here } when "this" becomes false, mean statements within conditional no longer execute, since conditions no longer being met, or rest of statement "//other code here" still executed? have been careful not change state of conditional until done doing whatever need conditional, curious if necessary in first place. time.
no, condition in statement tested @ point says if(this) [1] - after that, can change value anyway like, , code continue.
note concept holds true while(condition) { ... } - condition chcked @ beginning of loop, code continues sequentially there, until goes beginning of loop again.
it common pattern this:
need_print_heading = true; lines = 0; while(more_data) { if (need_print_heading) { need_print_heading = false; print_heading(); } print_data(); linex++; if (lines > 50) need_print_heading = true; } [1] use of this in code showing means it's invalid c++, since this reserved word in c++. need change name make code compile.
Comments
Post a Comment