Page 194 - Computer science 868 Class 12
P. 194
System.out.print("Enter a number: ");
n=sc.nextInt();
if(n == 0)
break;
if(n%2==0)
sum=sum+n;
}
System.out.println("Sum of even number : " + sum);
}
}
7.4.2 continue
The continue statement works opposite to the break statement. Here, the control of the loop is sent to the next
iteration on executing the continue statement. It works only with the loop statements.
For example:
Input 10 numbers and print the sum of all the even numbers.
class sum_of_even
{
public static void main()
{
int i, s=0;
for(i=1; i<=10; i++)
{
if(i%2==1)
{
continue;
}
s=s+i;
}
System.out.println("Sum of even numbers "+ s);
}
}
7.4.3 return
The return statement transfers the control to the caller program during the method call. It is generally the last statement
in the method. But, sometimes it is required to exit with a condition. In this case, we require the return statement.
We can also send back any value to the caller method using this statement.
Syntax:
Returntype function_name(arguments)
{
Job of the method;
return statement;
}
192192 Touchpad Computer Science-XII

