0% found this document useful (0 votes)
9 views5 pages

Module2 Additional Notes

Uploaded by

Vinodh Gau
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views5 pages

Module2 Additional Notes

Uploaded by

Vinodh Gau
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

goto Statement in C

The goto statement in C allows the program to jump to some


part of the code, giving you more control over its execution.

Syntax
Syntax1
goto label;
……..
……..
label:

Syntax 2
Label:
……..
……..
goto label;
Example program:
#include <stdio.h>
void main()
{
int n = 0;
if (n == 0)
goto jump_here;
printf("You entered: %d\n", n);
jump_here:
printf("Exiting the program.\n");
return 0;
}
Write a C program to check whether a given number is even or odd.
The program should use two goto statements to jump to the labels even and
odd for printing the result.

#include <stdio.h>
int main() {
int n = 26;

if (n % 2 == 0)

// jump to even
goto even;
else

// Jump to odd
goto odd;

even:
printf("%d is even", n);
return 0;

odd:
printf("%d is odd", n);
return 0;
}
Continue Statement in C
The continue statement in C is a jump statement used to skip
the current iteration of a loop and continue with the next
iteration. It is used inside loops (for, while, or do-while) along
with the conditional statements to bypass the remaining
statements in the current iteration and move on to the next
iteration.
#include <stdio.h>
int main() {

// Loop from 1 to 5
for (int i = 1; i <= 5; i++) {

// Skip number 3
if (i == 3)
continue;
printf("%d ", i);
}
}
Output
1 2 4 5
Break Statement in C
The break statement in C is a loop control statement that breaks
out of the loop when encountered. It can be used inside loops or
switch statements to bring the control out of the block. The
break statement can only break out of a single loop at a time.
#include <stdio.h>
void main() {
for (int i = 1; i <= 10; i++) {
// Exit the loop when i equals 5
if (i == 5) {
break;
}
printf("%d ", i);
}
}
Output
1 2 3 4
Syntax of Ternary Operator
The syntax of ternary operator is:

testCondition ? expression1 : expression 2;

The testCondition is a boolean expression that results in


either true or false. If the condition is
 true - expression1 (before the colon) is executed
 false - expression2 (after the colon) is executed

#include <stdio.h>
void main() {
int age;
// take input from users
printf("Enter your age: ");
scanf("%d", &age);
// ternary operator to find if a person can vote or not
(age >= 18) ? printf("You can vote") : printf("You cannot vote");
return 0;
}
Dhanusree
Ben
Deva
Madhav
Izhana
Arpitha

You might also like