Hello guys. I hope you Guys have read my previous tutorials. Today I'm going to discuss about the major loops in the programing.
1) For loop
The for-loop has four parts -- init, test, increment, and body -- separated by semi-colons (;)
The for-loop is used specifically to step a variable through a sequence
of values, such as 0, 1, 2, 3, ..9 In fact, most for-loops adhere to
that pattern so closely, that they will look similar to the 0..99for-loop code below.
- Init
- Test
The boolean test is evaluated. If it is true the loop body will execute (green light, just like a while-loop). Typically, the test is a boolean expression such as "i<100", showing what should be true for the loop to continue.
- Loop-body
- increment or decrement
2) while loop
Since the while-loop checks the test before every iteration, it is possible for the body to not run even once. While loop is consists of three parts.
- test
- work
- increment or decrement
3) Do-While loop
The do-while loop executes a block of code while a boolean expression
evaluates to true. It checks the boolean expression after each
iteration. It terminates as soon as the expression evaluates to false. Do-while loop evaluates the boolean expression at the end of
the iteration, the block of code within the loop is guaranteed to run
at least once.
Fact given below is common for every loop.
- boolean Expression results in either a true or false output. It is created using comparing operators (==, >, =, <=, !=).
- There can also be multiple boolean expressions within the parentheses (boolean Expression). The boolean expressions are connected through logical operators (&&, ||, !).
See you guys in next tutorials
No comments:
Post a Comment