Syntax for Nested if Statements:
if (expression){Block of statements;} else if(expression) {elseBlock of statements; } {}Block of statements;
Loops:
Sometimes, we need to print a series of numbers or some block of contents for certain number of times, The major difference between branching and loop statement that the branching statements will execute the statements only one time, but the loop statement will execute mentioned number of times. We start with while loops and then go on to show this can be converted to do-while and for loops.
while loop
The most basic loop in C is the while loop. A while statement is like a repeating if statement. Like an If statement, if the test condition is true: the statements get executed. The difference is once the statement have been executed, the condition in the while parenthesis is checked again. If it is still true the statements get executed again.This cycle repeats until the test condition evaluates to false.
Basic syntax of while loop is as follows:
Syntax of While loop:
while ( condition )
{
Single statement
or
Block of statements;
}
|
Comments
Post a Comment