Execute both if and else Statements in C/C++ SimultaneouslyIf-else statements are designed as plan-a backing plan-b. If plan-a fails, plan-b comes into the picture. How can we make both the conditionals work? The trick we apply to solve this chicken-and-egg problem in C and C++ is we use the goto function. The goto function links both the conditionals in such a way that if one gets executed, the execution of the following boolean executes as well simultaneously. Syntax of if-else statements in C/C++ language is C Code(if-else) Output: j variable is greater than 15 C++ Code(if-else) Output: j variable is greater than 15 Syntax Nested if-else statements are special conditions; here, conditionals are either undirected or directed one inside the other. The nested if-else statements can be compared with nested for loops and nested while loops. Implementing nested if-else statements is discussed in C and C++ programming languages. Nested if-else in C Output: j is smaller than 15 j is smaller than 12 too Nested if-else in C++ Output: j is smaller than 15 j is smaller than 12 too Below we are writing down the code to execute both if and else statements together. To achieve this task, we will use the goto function and label them to the next targetted conditional statement. It can either be an else statement or another if statement, which is nested if. C Code Output: Hello JTP C++ Code Output: Hello JTP |
JavaTpoint offers too many high quality services. Mail us on h[email protected], to get more information about given services.
JavaTpoint offers college campus training on Core Java, Advance Java, .Net, Android, Hadoop, PHP, Web Technology and Python. Please mail your requirement at [email protected].
Duration: 1 week to 2 week