Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 2

Write Short Note on break statement. Break statement is used to come out of a loop or case statement.

When a loop runs normally, it runs till the loops evaluating (testing) condition remains true. However, if it is required to abrupt come out of loop, break statement is used for that. It can be used inside a loop (or switch statement) as follows: any loop() { } break;

However, if it placed unconditionally as above, it will come out of the loop very first time. So, it must be placed in an addition condition as follows. any loop() { Condition() break;

Here, if condition gets satisfied at any point, break will be executed and control will be placed outside loop. If condition do not ever gets satisfied, loop runs normally and terminates only when testing condition evaluates to false. Example: For(i=2;i<=n-1;i++) { If(n%i==0) Break; } Continue statement is used to skip statements from condition to rest of loop. Some portion of a loop block is not required to run when a certain condition evaluate to true, such portion is placed beneath continue as follows. any loop() { Condition() continue;

} Example: For(i=1;i<=30;i++) { If(i%3==0) Continue; Printf(%d\t,i); } Type cast: When we want to process two different type of numeric operand with an operator, the operand with the smaller data type gets converted into larger data type. This happens automatically and is known as implicit type casting. Example: Int a; Float b; Printf(%f,b+a); Here a is integer and added into float b. So, before being added, it gets converted into float first.

In case, we want to forcibly convert a numeric operand (or a simple number), we can place the data type we wish in front of the number in a bracket. This is known as explicit type casting (or conversion).

You might also like