1 / 9

Jump Statement

Jump Statement. Three jump statements Break, continue and return. Break and Continue with the nested loop. result: j 1 and 2) only. break. Break as a form goto. A break statement exits a loop before an entry condition fails.

lwooldridge
Télécharger la présentation

Jump Statement

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Jump Statement • Three jump statements • Break, continue and return

  2. Break and Continue with the nested loop result: j 1 and 2) only break

  3. Break as a form goto • A break statement exits a loop before an entry condition fails. • The break statement can also be employed by itself to provide a form of “goto”. The format is: break label:

  4. Example – use break to exit from loop break once it becomes negative

  5. Continue - Explanation • Sometimes it is necessary to exit from the middle of a loop. • Sometimes we want to start over at the top of the loop. • Sometimes we want to leave the loop completely. For Example for (int i = 0; i < length; i++) { if (m[i] % 2 == 0) continue; // process odd elements... } it will process the odd case

  6. Example - continue 1, 3, 5, 7 are missing

  7. Return • It has purpose to exit from the current method • It jumps back to the statement within the calling method that follows the original method call. Example • return expression

  8. Example

  9. Summary • Selection Statements • If and switch • Iteration Statements • While, do-while, for and nested loops • Jump Statements • Break, continue and return

More Related