Question

Write a program in C++ or Java which determines the scope of the control variable declared...

Write a program in C++ or Java which determines the scope of the control variable declared in a while loop. Your program must determine whether the control variable is visible after the loop’s body.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

`Hey,

Note: Brother if you have any queries related the answer please do comment. I would be very happy to resolve all your queries.

Below program when run will lead to an error which tells us that control variable is not visible after loop

public class Main
{
   public static void main(String[] args) {
int ct=0;
while(ct<=10)
{
int j=1;
  
ct++;
}
try {
System.out.println(j);
System.out.println("It is visible outside loop");
} catch(Exception e) {
System.out.println("It is not visible outside loop");
}
  
  
   }
}

Kindly revert for any queries

Thanks.

Add a comment
Know the answer?
Add Answer to:
Write a program in C++ or Java which determines the scope of the control variable declared...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT