Jumping Statements in c
Solution
Jumping statements in C are used to pass control from one part of the program to another. There are four types of jumping statements in C: break, continue, goto, and return.
- Break: The break statement is used to terminate the loop or switch statement and transfer execution to the statement immediately following the loop or switch.
Example:
for (int i = 0; i < 10; i++) {
if (i == 5) {
break;
}
printf("%d ", i);
}
In this example, the loop will terminate when i equals 5.
- Continue: The continue statement is used to end the current iteration of the loop statement and begin the next iteration.
Example:
for (int i = 0; i < 10; i++) {
if (i == 5) {
continue;
}
printf("%d ", i);
}
In this example, when i equals 5, the current iteration of the loop will end, and the loop will continue with the next iteration.
- Goto: The goto statement is used to transfer control to the labeled statement.
Example:
int i = 0;
label:
if (i < 10) {
printf("%d ", i);
i++;
goto label;
}
In this example, the goto statement will cause the program to jump back to the label statement until i is no longer less than 10.
- Return: The return statement is used to end the execution of a function and return control to the calling function.
Example:
int add(int a, int b) {
return a + b;
}
In this example, the return statement will end the execution of the add function and return the result of a + b to the calling function.
Similar Questions
Write Jumping and Branching Statements, If-Else Statements, Looping Statements in C
Suppose that in a C program snippet, followings statements are used
Which of these loop statements exist in C?
What does the following statement in C signify?
BC220415117: SYEDA LAIBA SHAH Time Left 89 sec(s) CS401P - Computer Architecture and Assembly Language Programming (Practical) (Lab Quiz No. 2 (Non-Graded)) Quiz Start Time: 11:00 AM, 29 April 2024 Question # 4 of 5 ( Start time: 11:02:19 AM, 29 April 2024 ) Total Marks: 1 Which of following jump instruction is an unconditional jump? Select the correct optionReload Math Equations jns jnz jcxz jmp
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.