Page 89 - iPro_trackGPT_V5_Class8
P. 89

In the preceding program, the continue statement stops the execution of the iteration
                 (i == 5) of the for loop. The for loop will be executed normally for all other values of the
                 variable i.

                    ERRORS IN JAVA

                 An error is an abnormal condition that can stop the execution of a program. There are three
                 types of errors in Java: syntax errors, runtime errors, and logical errors. Let us learn about
                 these in detail.
                 Syntax Errors

                 Syntax errors occur when the rules of Java syntax are not followed. These are among the
                 most common types of mistakes made while writing Java programs and are also known as
                 compile-time errors. If your code contains syntax errors, it will not compile, meaning the
                 program won’t run until these errors are fixed.
                 Examples of syntax errors include: forgetting a semicolon at the end of a statement, adding
                 an extra or missing bracket, misspelling keywords or variable names, etc. For example,

                 public class SyntaxError{
                        public static void main(String args[])

                        {
                               int a = 100;

                               int b = 200;
                               int c = a * b

                               System.out.println(c);
                        }
                 }

                 }

                 In the preceding program, the statement "int c = a * b" produces an error because we have
                 not added the semicolon at the end of the line. We have also added an extra bracket at the
                 end of the class. So, the compiler shows an error message for the same.
                 Runtime Errors

                 A runtime error occurs while the program is running, after it has been successfully compiled.
                 These errors happen when the program encounters unexpected situations or conditions that
                 it cannot handle. Unlike syntax errors, which are caught by the compiler, runtime errors only
                 show up during the program's execution. For example, dividing a number by zero can cause
                 a runtime error. To fix runtime errors, you need to identify and handle these problems in
                 your code so that the program can run smoothly. For example,

                 public class RuntimeError{
                        public static void main(String args[])

                        {



                                                                Conditional, Looping and Jump Statements in Java  87
   84   85   86   87   88   89   90   91   92   93   94