Please explain break and continue on Objective-C -


Firstly excuse my newbie question I am learning the purpose and I am very new to programming.

Can you tell me what causes a break or what happens inside a loop?

For example, two codes?

 for  (int i = 0; i & lt; 100; i ++) {if ([looks correct itself]) {[do something self]; } And {break} }} For   

and

  (int i = 0; i & lt; 100; i ++) {if ([self okToProceed]) {[Self doSomething]; } And {continue; }}   

Can the first code loop be stopped for the first time? OK to return to hacking, the repatriation is wrong and the second loop bus continues to run, but okToProceed is nothing wrong Has been doing?

A break statement exits the loop.
You can think of it as a means of making a loop

For example, in your code: for (int i = 0; i & lt; 100; i ++ ) , i is the status of a loop.
Loop will stop if this situation is not completed.

Similarly, if you have something like this, then if (i == 34) {break; } .
It will exit from the loop when the value of i reaches 34, although the specified loop exhaust status i & lt; 100 .


A continue statement is used to move to the next loop cycle.
This statement is basically used to avoid running the rest of the loop.

Example:

 For  (i = 0; i <5; i ++) {if (i == 3) {continue; } Print (i); }   

This will print the loop 0 1 2 4 .
When i will be 3, continue the next loop will skip the recurrence and continue ( i.e. print ( I); will not execute ) after the statement.
Of course, the status of the loop is checked before the loop run.

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -