Infinite Loop

An infinite loop is one which keeps on running for all values of loop variables involved. Essentially, the reason for an infinite loop is that the condition for the loop is always true.

Example: Write a program using ‘*’ showing infinite loop.

Code:

q1

q1..png

goto Statement:

                               The word written after goto is called a label. The label can be any word and it is not to be declared or initialized first like a variable. The difference between a break statement and goto statement is that , when the loop ends using a break statement the program execution continues after the for loop for the goto statement the program execution will start from the label to which the goto statement is directed.

 Example: Write a program  showing ‘*’  using goto statement.

Code:

q2.png

q2..png

Example:

Code:

q3

q3..png

Switch statement:

Switch statement is similar to an if-else structure studied earlier. In switch statement, the option selected by user is compared against all the available cases and the appropriate case is executed. The basic syntax of switch statement is

Syntax:

initialization;

switch(variable)

{

case c1:

statement( );

break;

case c2:

statement( );

break;

.

.

.

default:

statements( );

break;

}

Example:Write a program to determine that student is pass or fail.

Code

q4

q4..png

Example:Write a program to choose the arithmetic operation.

Code:

q5.png

q5..png

Previous Page:

-Arrays

https://www.electricalengineering4u.com/fundamentals-of-programming/arrays-in-c/

Next page

-C++ Functions

https://www.electricalengineering4u.com/fundamentals-of-programming/c-functions/