Welcome back, on this post I’ll give you a summary about Repetition on C language.
Repetition has similar algorithmic pattern if you compare it with ‘If’ function except it call it’s function again when the the condition given still true. In C language, repetition category consist of 3 function, While, For, and Do-While.
“While” is the most simple repetition, you can put wide range of condition into it. but to make the looping end you need to make the condition false inside the statement, except you want an endless loop.
“For” has the same algorithm like “While” but it has the initialization and increment or decrement packed along with to the conditional expression, it saves some lines of coding and make the syntax simpler to use but it make the range of conditional expression is limited.
“Do-While” has a reversed order if it compared with while, it runs the statement first before do the conditional checking.
Like the selection, Repetition has a nested form, the logic is like this, there is two repetition, Loop A and loop B, Loop B is in the Loop A, when the program started the loop A run and execute the loop B, loop B do the repetition until the condition on Loop B turns false, after that the Loop A do conditional check, if it’s condition still true it will execute Loop B again.